Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/actions/get-pr-deployments/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Get PR Deployments

Action that returns the number of deployments on a given PR branch.

## Inputs

| Name | Description | Required | Default | Example |
| ---- | ----------- | -------- | ------- | ------- |
| `pr` | The pull request number to check for deployments of all kinds | `true` | N/A | `21` |
| `repository` | The repository to check for deployments | `false` | Value of `github.repository` | `"ACCESS-NRI/ACCESS-OM2"` |
| `token` | The GitHub token to use for API requests | `false` | Value of `github.token` | `"ghp_XXXX"` |

## Outputs

| Name | Description | Example |
| ---- | ----------- | ------- |
| `deployments` | The total number of deployments for the given PR (from commits and `!redeploy`s) | `24` |

## Example

```yaml
# ...
jobs:
deployments:
runs-on: ubuntu-latest
steps:
- id: pr-deploys
uses: access-nri/build-cd/.github/actions/get-pr-deployments@v6
with:
pr: 12

- run: echo "There have been ${{ steps.pr-deploys.outputs.deployments }} total deployments in this PR, including both regular commit deployments and redeployments"
```
71 changes: 71 additions & 0 deletions .github/actions/get-pr-deployments/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Get PR Deployments
description: Action that returns how many deployments were made in a PR (both from commits and !redeploys)
author: Tommy Gatti
inputs:
pr:
required: true
description: The pull request number to check for deployments of all kinds
repository:
required: false
default: ${{ github.repository }}
description: The repository to check for deployments
token:
required: false
default: ${{ github.token }}
description: The GitHub token to use for API requests
outputs:
deployments:
description: The total number of deployments for the given PR (from commits and !redeploys)
value: ${{ steps.total.outputs.number }}
runs:
using: composite
# Essentially, count all the deployment entries that match the given branch, as well as
# all the `!redeploy` comments, to get the next deployment number.
# See https://docs.github.com/en/rest/deployments/deployments?apiVersion=2022-11-28#list-deployments
steps:
- name: Get PR HEAD
id: pr
shell: bash
env:
GH_TOKEN: ${{ inputs.token }}
run: |
head=$(gh pr view ${{ inputs.pr }} --repo ${{ inputs.repository }} --json headRefName --jq .headRefName)
echo "HEAD of PR #${{ inputs.pr }} in ${{ inputs.repository }} is $head"
echo "head=$head" >> $GITHUB_OUTPUT

- name: Get commit deployments for PR
id: commit
shell: bash
env:
GH_TOKEN: ${{ inputs.token }}
# We --slurp the results because --paginate introduces potentially multiple array results
run: |
deployments=$(gh api \
-H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \
--paginate --slurp \
/repos/${{ inputs.repository }}/deployments \
| jq '[select(.[][].ref == "${{ steps.pr.outputs.head }}")] | length'
)
echo "Found $deployments deployments for PR #${{ inputs.pr }} in ${{ inputs.repository }}"
echo "deployments=$deployments" >> $GITHUB_OUTPUT

- name: Get !redeploys from comments
id: comment
shell: bash
env:
GH_TOKEN: ${{ inputs.token }}
run: |
redeployments=$(gh pr view ${{ inputs.pr }} --repo ${{ github.repository }} \
--json comments \
--jq '[.comments[] | select(.body | startswith("!redeploy"))] | length'
)
echo "Found $redeployments redeploy comments for PR #${{ inputs.pr }} in ${{ inputs.repository }}"
echo "redeployments=$redeployments" >> $GITHUB_OUTPUT

- name: Return total deployments
id: total
shell: bash
run: |
total=$(( ${{ steps.commit.outputs.deployments }} + ${{ steps.comment.outputs.redeployments }} ))
echo "Found $total deployments across commits (${{ steps.commit.outputs.deployments }}) and redeploys (${{ steps.comment.outputs.redeployments }}) for PR #${{ inputs.pr }} in ${{ inputs.repository }}"
echo "number=$total" >> $GITHUB_OUTPUT
8 changes: 4 additions & 4 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:

- name: Generate Deployment Target Matrix
id: target
uses: access-nri/build-cd/.github/actions/get-target-matrix@v6
uses: access-nri/build-cd/.github/actions/get-target-matrix@v7
with:
targets: ${{ vars.RELEASE_DEPLOYMENT_TARGETS }}

Expand All @@ -108,7 +108,7 @@ jobs:
with:
repository: access-nri/build-cd

- uses: access-nri/build-cd/.github/actions/validate-deployment-settings@v6
- uses: access-nri/build-cd/.github/actions/validate-deployment-settings@v7
with:
settings-path: ./config/settings.json
target: ${{ matrix.target }}
Expand All @@ -126,7 +126,7 @@ jobs:

- name: Get root spec ref
id: tag
uses: access-nri/build-cd/.github/actions/get-spack-root-spec@v6
uses: access-nri/build-cd/.github/actions/get-spack-root-spec@v7
with:
spack-manifest-path: ${{ inputs.spack-manifest-path }}

Expand Down Expand Up @@ -180,7 +180,7 @@ jobs:
strategy:
matrix:
target: ${{ fromJson(needs.defaults.outputs.targets) }}
uses: access-nri/build-cd/.github/workflows/deploy-1-setup.yml@v6
uses: access-nri/build-cd/.github/workflows/deploy-1-setup.yml@v7
with:
deployment-target: ${{ matrix.target }}
deployment-ref: ${{ github.ref_name }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-closed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

- name: Generate Deployment Target Matrix
id: target
uses: access-nri/build-cd/.github/actions/get-target-matrix@v6
uses: access-nri/build-cd/.github/actions/get-target-matrix@v7
with:
targets: ${{ vars.PRERELEASE_DEPLOYMENT_TARGETS }}

Expand All @@ -50,7 +50,7 @@ jobs:
matrix:
target: ${{ fromJson(needs.setup.outputs.targets) }}
fail-fast: false
uses: access-nri/build-cd/.github/workflows/undeploy-1-start.yml@v6
uses: access-nri/build-cd/.github/workflows/undeploy-1-start.yml@v7
with:
version-pattern: ${{ inputs.root-sbd }}-pr${{ github.event.pull_request.number }}-*
target: ${{ matrix.target }}
Expand Down
Loading