From 8c98187e2998feda45715f50d62c5638268a7a99 Mon Sep 17 00:00:00 2001 From: Jesse Newland Date: Fri, 12 May 2023 16:51:20 -0500 Subject: [PATCH 1/7] Fix log url --- .github/workflows/pr-preview.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/pr-preview.yaml b/.github/workflows/pr-preview.yaml index 2d716b7..9d40da7 100644 --- a/.github/workflows/pr-preview.yaml +++ b/.github/workflows/pr-preview.yaml @@ -3,7 +3,13 @@ on: pull_request: jobs: + prepare: + runs-on: ubuntu-latest + steps: + - run: 'true' + deploy: + needs: prepare runs-on: ubuntu-latest steps: - name: Checkout From e879e4494e9d6b74b9c7061810fbd5a6dd3157e9 Mon Sep 17 00:00:00 2001 From: Jesse Newland Date: Fri, 12 May 2023 17:08:07 -0500 Subject: [PATCH 2/7] deploy logs --- action.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index a9483d0..5a0fda6 100644 --- a/action.yml +++ b/action.yml @@ -29,6 +29,10 @@ inputs: description: | A Github token. `secrets.GITHUB_TOKEN`` is fine for start and finish steps. default: "" + log_url_job_name: + description: | + Name of the step to use for the Deployment's log URL. Case-insensitive. Defaults to `deploy` + default: deploy outputs: deployment_id: @@ -50,15 +54,18 @@ runs: if: ${{ inputs.step == 'start' || inputs.step == 'finish' }} uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1 id: job-url + env: + JOB_NAME: ${{ input.log_url_job_name }} with: script: | - const { data } = await github.rest.actions.listJobsForWorkflowRunAttempt({ + const jobs = await github.paginate(github.rest.actions.listJobsForWorkflowRunAttempt, { ...context.repo, run_id: context.runId, attempt_number: process.env.GITHUB_RUN_ATTEMPT, }); - return data.jobs.pop().html_url + return jobs.find(job => job.name.toLowerCase() == process.env.JOB_NAME.toLowerCase())?.html_url; + result-encoding: string - name: Start deployment From 16d1c323dcf7011d98ff293c97cbcb46af00c519 Mon Sep 17 00:00:00 2001 From: Jesse Newland Date: Fri, 12 May 2023 17:09:17 -0500 Subject: [PATCH 3/7] plural --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 5a0fda6..b33280b 100644 --- a/action.yml +++ b/action.yml @@ -55,7 +55,7 @@ runs: uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1 id: job-url env: - JOB_NAME: ${{ input.log_url_job_name }} + JOB_NAME: ${{ inputs.log_url_job_name }} with: script: | const jobs = await github.paginate(github.rest.actions.listJobsForWorkflowRunAttempt, { From e7041ec814695a05559e8a7f4b4337d2d7daff3a Mon Sep 17 00:00:00 2001 From: Jesse Newland Date: Fri, 12 May 2023 17:13:13 -0500 Subject: [PATCH 4/7] default --- action.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index b33280b..173a364 100644 --- a/action.yml +++ b/action.yml @@ -64,7 +64,17 @@ runs: attempt_number: process.env.GITHUB_RUN_ATTEMPT, }); - return jobs.find(job => job.name.toLowerCase() == process.env.JOB_NAME.toLowerCase())?.html_url; + const matching = jobs.find(job => job.name.toLowerCase() == process.env.JOB_NAME.toLowerCase())?.html_url; + if (matching !== undefined) { + return matching; + } + + // if we didn't find the right job, pop the last two portions + // of the url off to get the summary of the workflow + const last = jobs.pop().html_url.split("/"); + last.pop(); + last.pop(); + return last.join("/"); result-encoding: string From 443be931d23a6cf3b67642ad206642d9c0e0d73e Mon Sep 17 00:00:00 2001 From: Jesse Newland Date: Fri, 12 May 2023 17:14:57 -0500 Subject: [PATCH 5/7] summary --- .github/workflows/pr-preview.yaml | 1 + .github/workflows/rollout-cleanup.yaml | 20 +++++++++++++ .github/workflows/rollout.yaml | 41 ++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 .github/workflows/rollout-cleanup.yaml create mode 100644 .github/workflows/rollout.yaml diff --git a/.github/workflows/pr-preview.yaml b/.github/workflows/pr-preview.yaml index 9d40da7..0cd28d5 100644 --- a/.github/workflows/pr-preview.yaml +++ b/.github/workflows/pr-preview.yaml @@ -38,3 +38,4 @@ jobs: deployment_id: ${{ steps.start.outputs.deployment_id }} env_url: https://pr-preview-${{ github.event.pull_request.number }}.example.com + \ No newline at end of file diff --git a/.github/workflows/rollout-cleanup.yaml b/.github/workflows/rollout-cleanup.yaml new file mode 100644 index 0000000..8ae7ad4 --- /dev/null +++ b/.github/workflows/rollout-cleanup.yaml @@ -0,0 +1,20 @@ +name: Rollout cleanup +on: + pull_request: + types: [ closed ] + +jobs: + prune: + runs-on: ubuntu-latest + steps: + - run: echo shutdown deployment + - name: Checkout + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 + - uses: ./ + name: Cleanup Preview deploy + with: + step: cleanup + env: rollout-${{ github.event.pull_request.number }} + app_id: ${{ secrets.RENOVATE_APP_ID }} + private_key: ${{ secrets.RENOVATE_APP_PEM }} + diff --git a/.github/workflows/rollout.yaml b/.github/workflows/rollout.yaml new file mode 100644 index 0000000..606047f --- /dev/null +++ b/.github/workflows/rollout.yaml @@ -0,0 +1,41 @@ +name: Rollout +on: + pull_request: + +jobs: + prepare: + runs-on: ubuntu-latest + steps: + - run: 'true' + + rollout: + needs: prepare + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 + - uses: ./ + name: Start preview deploy + id: start + with: + step: start + token: ${{ secrets.GITHUB_TOKEN }} + head_ref: ${{ github.head_ref }} + env: rollout-${{ github.event.pull_request.number }} + env_url: https://rollout-${{ github.event.pull_request.number }}.example.com + + - run: echo perform deploy + + - uses: ./ + name: Finish preview deploy + if: always() + with: + step: finish + status: ${{ job.status }} + token: ${{ secrets.GITHUB_TOKEN }} + head_ref: ${{ github.head_ref }} + env: rollout-${{ github.event.pull_request.number }} + + deployment_id: ${{ steps.start.outputs.deployment_id }} + env_url: https://rollout-${{ github.event.pull_request.number }}.example.com + \ No newline at end of file From c258dc37841cf775a54212bd110f8441acecac9c Mon Sep 17 00:00:00 2001 From: Jesse Newland Date: Fri, 12 May 2023 17:19:08 -0500 Subject: [PATCH 6/7] this is a much better default --- action.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 173a364..aee7270 100644 --- a/action.yml +++ b/action.yml @@ -31,8 +31,9 @@ inputs: default: "" log_url_job_name: description: | - Name of the step to use for the Deployment's log URL. Case-insensitive. Defaults to `deploy` - default: deploy + Name of the step to use for the Deployment's log URL. Case-insensitive. + Defaults to using the workflow summary url. + default: '' outputs: deployment_id: From 482b2e52ab0e840adf2dce1eab4b696b2e8533f8 Mon Sep 17 00:00:00 2001 From: Jesse Newland Date: Fri, 12 May 2023 17:19:41 -0500 Subject: [PATCH 7/7] positive example --- .github/workflows/rollout.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/rollout.yaml b/.github/workflows/rollout.yaml index 606047f..c100e9e 100644 --- a/.github/workflows/rollout.yaml +++ b/.github/workflows/rollout.yaml @@ -23,6 +23,7 @@ jobs: head_ref: ${{ github.head_ref }} env: rollout-${{ github.event.pull_request.number }} env_url: https://rollout-${{ github.event.pull_request.number }}.example.com + log_url_job_name: rollout - run: echo perform deploy @@ -38,4 +39,5 @@ jobs: deployment_id: ${{ steps.start.outputs.deployment_id }} env_url: https://rollout-${{ github.event.pull_request.number }}.example.com + log_url_job_name: rollout \ No newline at end of file