Skip to content

Commit

Permalink
Merge pull request #25 from urcomputeringpal/jnewland-patch-2
Browse files Browse the repository at this point in the history
Better log url
  • Loading branch information
jnewland authored May 12, 2023
2 parents 5357563 + 482b2e5 commit 10675e1
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/pr-preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -32,3 +38,4 @@ jobs:

deployment_id: ${{ steps.start.outputs.deployment_id }}
env_url: https://pr-preview-${{ github.event.pull_request.number }}.example.com

20 changes: 20 additions & 0 deletions .github/workflows/rollout-cleanup.yaml
Original file line number Diff line number Diff line change
@@ -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 }}

43 changes: 43 additions & 0 deletions .github/workflows/rollout.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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
log_url_job_name: rollout

- 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
log_url_job_name: rollout

22 changes: 20 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ 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 using the workflow summary url.
default: ''

outputs:
deployment_id:
Expand All @@ -50,15 +55,28 @@ runs:
if: ${{ inputs.step == 'start' || inputs.step == 'finish' }}
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
id: job-url
env:
JOB_NAME: ${{ inputs.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
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

- name: Start deployment
Expand Down

0 comments on commit 10675e1

Please sign in to comment.