diff --git a/.github/workflows/pr-preview.yaml b/.github/workflows/pr-preview.yaml index 2d716b7..0cd28d5 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 @@ -32,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..c100e9e --- /dev/null +++ b/.github/workflows/rollout.yaml @@ -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 + \ No newline at end of file diff --git a/action.yml b/action.yml index a9483d0..aee7270 100644 --- a/action.yml +++ b/action.yml @@ -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: @@ -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