From d9b03affd2e267ae87e39470a9dd41dbeadfc6c4 Mon Sep 17 00:00:00 2001 From: Janis Bebritis Date: Thu, 21 Mar 2024 16:24:56 +0200 Subject: [PATCH 1/2] test cci api change --- .github/workflows/release-test.yml | 63 ++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 .github/workflows/release-test.yml diff --git a/.github/workflows/release-test.yml b/.github/workflows/release-test.yml new file mode 100644 index 0000000..8118d0f --- /dev/null +++ b/.github/workflows/release-test.yml @@ -0,0 +1,63 @@ +name: Workflow test + +on: + push: + branches: [ feature/* ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + circleci-k8s-test-build: + name: Test released CLI + runs-on: ubuntu-latest + strategy: + matrix: + project: [ + {org: "wunderio", repo: "drupal-project-k8s", branch: "master"}, + {org: "wunderio", repo: "frontend-project-k8s", branch: "master"}, + {org: "wunderio", repo: "simple-project-k8s", branch: "master"} + ] + steps: + - uses: actions/checkout@v4 + - name: Validate released cli with ${{ matrix.project.REPO_NAME }} + run: | + REPO_NAME="${{ matrix.project.repo }}" + ORG_NAME="${{ matrix.project.org }}" + BRANCH_NAME="${{ matrix.project.branch }}" + CIRCLECI_DEV_API_TOKEN_B64=$(echo -n "${{ secrets.CIRCLECI_DEV_API_TOKEN }}:" | base64) + + if [ -z "${{ secrets.CIRCLECI_DEV_API_TOKEN }}" ]; then + echo "Repository secrets is missing CIRCLECI_DEV_API_TOKEN variable." + exit 1 + fi + + echo "Running ${ORG_NAME}/${REPO_NAME}/${BRANCH_NAME} build on CircleCI" + echo "Project link: https://app.circleci.com/pipelines/github/${ORG_NAME}/${REPO_NAME}?branch=${BRANCH_NAME}" + + # Trigger a new pipeline + PIPELINE_ID=$(curl --request POST \ + --url "https://circleci.com/api/v2/project/gh/wunderio/${REPO_NAME}/pipeline" \ + --header "content-type: application/json" \ + --data "{\"branch\":\"${BRANCH_NAME}\"}" \ + --header "authorization: Basic ${CIRCLECI_DEV_API_TOKEN_B64}" --silent | jq -r '.id') + + echo "Pipeline ID: ${PIPELINE_ID}" + + sleep 10 + + # Wait for pipeline to be complete + while true; do + PIPELINE_STATUS=$(curl --request GET \ + --url "https://circleci.com/api/v2/pipeline/${PIPELINE_ID}/workflow" \ + --header "authorization: Basic ${CIRCLECI_DEV_API_TOKEN_B64}" --silent | jq -r '.items[0].status') + if [ "${PIPELINE_STATUS}" = "success" ]; then + echo "Pipeline completed successfully" + break + elif [ "${PIPELINE_STATUS}" != "created" ] && [ "${PIPELINE_STATUS}" != "running" ]; then + echo "Pipeline status: ${PIPELINE_STATUS}, failing the test" + exit 1 + fi + echo "current status: ${PIPELINE_STATUS}" + sleep 10 + done \ No newline at end of file From d96ffee742ef634ec57b5ac2214aaa4b1522965b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=81nis=20Bebr=C4=ABtis?= Date: Thu, 21 Mar 2024 16:38:07 +0200 Subject: [PATCH 2/2] Using CircleCI v2 API for test deployment triggers; checkout action update --- .github/workflows/release-test.yml | 63 ----------------------------- .github/workflows/release.yml | 64 ++++++++++++++++++------------ 2 files changed, 39 insertions(+), 88 deletions(-) delete mode 100644 .github/workflows/release-test.yml diff --git a/.github/workflows/release-test.yml b/.github/workflows/release-test.yml deleted file mode 100644 index 8118d0f..0000000 --- a/.github/workflows/release-test.yml +++ /dev/null @@ -1,63 +0,0 @@ -name: Workflow test - -on: - push: - branches: [ feature/* ] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -jobs: - circleci-k8s-test-build: - name: Test released CLI - runs-on: ubuntu-latest - strategy: - matrix: - project: [ - {org: "wunderio", repo: "drupal-project-k8s", branch: "master"}, - {org: "wunderio", repo: "frontend-project-k8s", branch: "master"}, - {org: "wunderio", repo: "simple-project-k8s", branch: "master"} - ] - steps: - - uses: actions/checkout@v4 - - name: Validate released cli with ${{ matrix.project.REPO_NAME }} - run: | - REPO_NAME="${{ matrix.project.repo }}" - ORG_NAME="${{ matrix.project.org }}" - BRANCH_NAME="${{ matrix.project.branch }}" - CIRCLECI_DEV_API_TOKEN_B64=$(echo -n "${{ secrets.CIRCLECI_DEV_API_TOKEN }}:" | base64) - - if [ -z "${{ secrets.CIRCLECI_DEV_API_TOKEN }}" ]; then - echo "Repository secrets is missing CIRCLECI_DEV_API_TOKEN variable." - exit 1 - fi - - echo "Running ${ORG_NAME}/${REPO_NAME}/${BRANCH_NAME} build on CircleCI" - echo "Project link: https://app.circleci.com/pipelines/github/${ORG_NAME}/${REPO_NAME}?branch=${BRANCH_NAME}" - - # Trigger a new pipeline - PIPELINE_ID=$(curl --request POST \ - --url "https://circleci.com/api/v2/project/gh/wunderio/${REPO_NAME}/pipeline" \ - --header "content-type: application/json" \ - --data "{\"branch\":\"${BRANCH_NAME}\"}" \ - --header "authorization: Basic ${CIRCLECI_DEV_API_TOKEN_B64}" --silent | jq -r '.id') - - echo "Pipeline ID: ${PIPELINE_ID}" - - sleep 10 - - # Wait for pipeline to be complete - while true; do - PIPELINE_STATUS=$(curl --request GET \ - --url "https://circleci.com/api/v2/pipeline/${PIPELINE_ID}/workflow" \ - --header "authorization: Basic ${CIRCLECI_DEV_API_TOKEN_B64}" --silent | jq -r '.items[0].status') - if [ "${PIPELINE_STATUS}" = "success" ]; then - echo "Pipeline completed successfully" - break - elif [ "${PIPELINE_STATUS}" != "created" ] && [ "${PIPELINE_STATUS}" != "running" ]; then - echo "Pipeline status: ${PIPELINE_STATUS}, failing the test" - exit 1 - fi - echo "current status: ${PIPELINE_STATUS}" - sleep 10 - done \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3171e90..e704ccc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,7 +16,7 @@ jobs: goos: [linux, darwin, windows] goarch: [amd64, arm64] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: azure/setup-helm@v3 with: version: 'v3.6.3' @@ -38,7 +38,7 @@ jobs: goos: [linux, windows] goarch: [amd64, arm64] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set output id: vars run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT @@ -57,36 +57,50 @@ jobs: strategy: matrix: project: [ - {repo: "drupal-project-k8s", jobs: "4"}, - {repo: "frontend-project-k8s", jobs: "4"}, - {repo: "simple-project-k8s", jobs: "3"} + {org: "wunderio", repo: "drupal-project-k8s", branch: "master"}, + {org: "wunderio", repo: "frontend-project-k8s", branch: "master"}, + {org: "wunderio", repo: "simple-project-k8s", branch: "master"} ] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Validate released cli with ${{ matrix.project.REPO_NAME }} run: | REPO_NAME="${{ matrix.project.repo }}" - JOB_COUNT="${{ matrix.project.jobs }}" - CIRCLECI_DEV_API_TOKEN="${{ secrets.CIRCLECI_DEV_API_TOKEN }}" + ORG_NAME="${{ matrix.project.org }}" + BRANCH_NAME="${{ matrix.project.branch }}" + CIRCLECI_DEV_API_TOKEN_B64=$(echo -n "${{ secrets.CIRCLECI_DEV_API_TOKEN }}:" | base64) - if [ -z "${REPO_NAME}" ] || [ -z "${CIRCLECI_DEV_API_TOKEN}" ] || [ -z "${JOB_COUNT}" ]; then - echo "Missing CIRCLECI_DEV_API_TOKEN secret" - exit 1 + if [ -z "${{ secrets.CIRCLECI_DEV_API_TOKEN }}" ]; then + echo "Repository secrets is missing CIRCLECI_DEV_API_TOKEN variable." + exit 1 fi - echo "Running ${REPO_NAME} build on CircleCI" - echo "Project link: https://circleci.com/gh/wunderio/workflows/${REPO_NAME}" + echo "Running ${ORG_NAME}/${REPO_NAME}/${BRANCH_NAME} build on CircleCI" + echo "Project link: https://app.circleci.com/pipelines/github/${ORG_NAME}/${REPO_NAME}?branch=${BRANCH_NAME}" + + # Trigger a new pipeline + PIPELINE_ID=$(curl --request POST \ + --url "https://circleci.com/api/v2/project/gh/wunderio/${REPO_NAME}/pipeline" \ + --header "content-type: application/json" \ + --data "{\"branch\":\"${BRANCH_NAME}\"}" \ + --header "authorization: Basic ${CIRCLECI_DEV_API_TOKEN_B64}" --silent | jq -r '.id') + + echo "Pipeline ID: ${PIPELINE_ID}" - base_api_url="https://circleci.com/api/v1.1/project/github/wunderio/${REPO_NAME}" - # Trigger a new deployment. - curl -s -X POST $base_api_url/build?circle-token=${CIRCLECI_DEV_API_TOKEN} - sleep 10 - # Wait for deployment to be complete - while curl -s "$base_api_url?circle-token=${CIRCLECI_DEV_API_TOKEN}&limit=${JOB_COUNT}" | jq -e 'any(.[]; (.status == "running") or (.status == "queued"))' > /dev/null - do - echo "still running" sleep 10 - done - # Test that the build was successful - curl -s "$base_api_url?circle-token=${CIRCLECI_DEV_API_TOKEN}&limit=${JOB_COUNT}" | jq '.[] | { job_name: .workflows.job_name, status: .status }' - curl -s "$base_api_url?circle-token=${CIRCLECI_DEV_API_TOKEN}&limit=${JOB_COUNT}" | jq -e 'all(.[]; .status == "success")' > /dev/null + + # Wait for pipeline to be complete + while true; do + PIPELINE_STATUS=$(curl --request GET \ + --url "https://circleci.com/api/v2/pipeline/${PIPELINE_ID}/workflow" \ + --header "authorization: Basic ${CIRCLECI_DEV_API_TOKEN_B64}" --silent | jq -r '.items[0].status') + if [ "${PIPELINE_STATUS}" = "success" ]; then + echo "Pipeline completed successfully" + break + elif [ "${PIPELINE_STATUS}" != "created" ] && [ "${PIPELINE_STATUS}" != "running" ]; then + echo "Pipeline status: ${PIPELINE_STATUS}, failing the test" + exit 1 + fi + echo "current status: ${PIPELINE_STATUS}" + sleep 10 + done \ No newline at end of file