From 3f86e8f8077d99afb4a92fea289077ace9b42fcd Mon Sep 17 00:00:00 2001 From: Stefan Judis Date: Wed, 26 Jul 2023 16:23:34 +0200 Subject: [PATCH] chore: update GitHub actions examples (#801) --- .../advanced-project-js/.github/workflow.yml | 35 ++++++++++++------- examples/advanced-project-js/package.json | 4 +-- .../advanced-project/.github/workflow.yml | 35 ++++++++++++------- examples/advanced-project/package.json | 4 +-- 4 files changed, 48 insertions(+), 30 deletions(-) diff --git a/examples/advanced-project-js/.github/workflow.yml b/examples/advanced-project-js/.github/workflow.yml index 6a006af8..d86611ce 100644 --- a/examples/advanced-project-js/.github/workflow.yml +++ b/examples/advanced-project-js/.github/workflow.yml @@ -2,24 +2,34 @@ # with providers like Vercel, Heroku and others. This workflow does the following # # - Runs after deployment event -# - Uses the target_url provided in the deployment event +# - Uses the environment_url provided in the deployment event # - Dry run all the checks on Checkly # - If the dry run passes, deploy the checks. # # You can of course trigger the Checkly CLI in other workflows or steps inside your GH Action configuration. -name: checkly +name: 'checkly' on: [deployment_status] + +# Set the necessary credentials and export variables we can use to instrument our test run. Use the ENVIRONMENT_URL +# to run your checks against staging, preview or production. env: - ENVIRONMENT_URL: ${{ github.event.deployment_status.target_url }} CHECKLY_API_KEY: ${{ secrets.CHECKLY_API_KEY }} CHECKLY_ACCOUNT_ID: ${{ secrets.CHECKLY_ACCOUNT_ID }} + ENVIRONMENT_URL: ${{ github.event.deployment_status.environment_url }} + CHECKLY_TEST_ENVIRONMENT: ${{ github.event.deployment_status.environment }} jobs: test-e2e: - if: github.event.deployment_status.state == 'success' + if: github.event.deployment_status.state == 'success' # Only run when the deployment was successful. name: Test E2E on Checkly runs-on: ubuntu-latest + timeout-minutes: 10 steps: - uses: actions/checkout@v3 + with: + ref: '${{ github.event.deployment_status.deployment.ref }}' + fetch-depth: 0 + - name: Set branch name # this is workaround to get the branch name. + run: echo "CHECKLY_TEST_REPO_BRANCH=$(git show -s --pretty=%D HEAD | tr -s ',' '\n' | sed 's/^ //' | grep -e 'origin/' | head -1 | sed 's/\origin\///g')" >> $GITHUB_ENV - uses: actions/setup-node@v3 with: node-version-file: '.nvmrc' @@ -32,12 +42,13 @@ jobs: - name: Install dependencies if: steps.cache-node-modules.outputs.cache-hit != 'true' run: npm ci - - name: Run checks + - name: Run checks # run the checks passing in the ENVIRONMENT_URL and recording a test session. id: run-checks - run: npm run checkly:test -- -e ENVIRONMENT_URL=${{ env.ENVIRONMENT_URL }} - continue-on-error: false - - name: Deploy checks - if: steps.run-checks.outcome == 'success' - run: npm run checkly:deploy - - + run: npx checkly -v && npx checkly test -e ENVIRONMENT_URL=${{ env.ENVIRONMENT_URL }} --reporter=github --record + - name: Create summary # export the markdown report to the job summary. + id: create-summary + run: cat checkly-github-report.md > $GITHUB_STEP_SUMMARY + - name: Deploy checks # if the test run was successful and we are on Production, deploy the checks + id: deploy-checks + if: steps.run-checks.outcome == 'success' && github.event.deployment_status.environment == 'Production' + run: npx checkly deploy --force diff --git a/examples/advanced-project-js/package.json b/examples/advanced-project-js/package.json index b3fa3c20..a1a702c5 100644 --- a/examples/advanced-project-js/package.json +++ b/examples/advanced-project-js/package.json @@ -5,9 +5,7 @@ "main": "index.js", "type": "commonjs", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "checkly:deploy": "npx checkly deploy --force", - "checkly:test": "npx checkly test" + "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", diff --git a/examples/advanced-project/.github/workflow.yml b/examples/advanced-project/.github/workflow.yml index 6a006af8..d86611ce 100644 --- a/examples/advanced-project/.github/workflow.yml +++ b/examples/advanced-project/.github/workflow.yml @@ -2,24 +2,34 @@ # with providers like Vercel, Heroku and others. This workflow does the following # # - Runs after deployment event -# - Uses the target_url provided in the deployment event +# - Uses the environment_url provided in the deployment event # - Dry run all the checks on Checkly # - If the dry run passes, deploy the checks. # # You can of course trigger the Checkly CLI in other workflows or steps inside your GH Action configuration. -name: checkly +name: 'checkly' on: [deployment_status] + +# Set the necessary credentials and export variables we can use to instrument our test run. Use the ENVIRONMENT_URL +# to run your checks against staging, preview or production. env: - ENVIRONMENT_URL: ${{ github.event.deployment_status.target_url }} CHECKLY_API_KEY: ${{ secrets.CHECKLY_API_KEY }} CHECKLY_ACCOUNT_ID: ${{ secrets.CHECKLY_ACCOUNT_ID }} + ENVIRONMENT_URL: ${{ github.event.deployment_status.environment_url }} + CHECKLY_TEST_ENVIRONMENT: ${{ github.event.deployment_status.environment }} jobs: test-e2e: - if: github.event.deployment_status.state == 'success' + if: github.event.deployment_status.state == 'success' # Only run when the deployment was successful. name: Test E2E on Checkly runs-on: ubuntu-latest + timeout-minutes: 10 steps: - uses: actions/checkout@v3 + with: + ref: '${{ github.event.deployment_status.deployment.ref }}' + fetch-depth: 0 + - name: Set branch name # this is workaround to get the branch name. + run: echo "CHECKLY_TEST_REPO_BRANCH=$(git show -s --pretty=%D HEAD | tr -s ',' '\n' | sed 's/^ //' | grep -e 'origin/' | head -1 | sed 's/\origin\///g')" >> $GITHUB_ENV - uses: actions/setup-node@v3 with: node-version-file: '.nvmrc' @@ -32,12 +42,13 @@ jobs: - name: Install dependencies if: steps.cache-node-modules.outputs.cache-hit != 'true' run: npm ci - - name: Run checks + - name: Run checks # run the checks passing in the ENVIRONMENT_URL and recording a test session. id: run-checks - run: npm run checkly:test -- -e ENVIRONMENT_URL=${{ env.ENVIRONMENT_URL }} - continue-on-error: false - - name: Deploy checks - if: steps.run-checks.outcome == 'success' - run: npm run checkly:deploy - - + run: npx checkly -v && npx checkly test -e ENVIRONMENT_URL=${{ env.ENVIRONMENT_URL }} --reporter=github --record + - name: Create summary # export the markdown report to the job summary. + id: create-summary + run: cat checkly-github-report.md > $GITHUB_STEP_SUMMARY + - name: Deploy checks # if the test run was successful and we are on Production, deploy the checks + id: deploy-checks + if: steps.run-checks.outcome == 'success' && github.event.deployment_status.environment == 'Production' + run: npx checkly deploy --force diff --git a/examples/advanced-project/package.json b/examples/advanced-project/package.json index 65ec746d..991134b0 100644 --- a/examples/advanced-project/package.json +++ b/examples/advanced-project/package.json @@ -5,9 +5,7 @@ "main": "index.js", "type": "commonjs", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "checkly:deploy": "npx checkly deploy --force", - "checkly:test": "npx checkly test" + "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC",