From f8ea968d43ba5eec48ab7e629c799284b7eff638 Mon Sep 17 00:00:00 2001 From: Gabe <41127686+Zidious@users.noreply.github.com> Date: Fri, 13 Oct 2023 21:38:59 +0100 Subject: [PATCH] feat(.github/actions): add `get-version-number-and-issue-url` action --- .../README.md | 37 +++++++++++++++++++ .../action.yml | 34 +++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 .github/actions/get-version-number-and-issue-url-v1/README.md create mode 100644 .github/actions/get-version-number-and-issue-url-v1/action.yml diff --git a/.github/actions/get-version-number-and-issue-url-v1/README.md b/.github/actions/get-version-number-and-issue-url-v1/README.md new file mode 100644 index 00000000..2418000f --- /dev/null +++ b/.github/actions/get-version-number-and-issue-url-v1/README.md @@ -0,0 +1,37 @@ +# get-version-number-and-issue-url-v1 + +This action gets the version number and issue url from the release-candidate. + +## Outputs + +| Output | Description | +| ---------------- | ----------------------------------------------------------- | +| `version-number` | The version number of the release candidate. | +| `issue-url` | The url of the issue associated with the release candidate. | + +## Example usage + +```yaml +name: Get version number and issue url and post to Slack + +on: push + +jobs: + post-to-slack: + runs-on: ubuntu-latest + steps: + - name: get version number and release-candidate issue URL + - uses: dequelabs/axe-api-team-public/.github/actions/get-version-number-and-issue-url-v1@main + id: get-version-number-and-issue-url + + - name: Slack Notification + # https://github.com/rtCamp/action-slack-notify/commit/b24d75fe0e728a4bf9fc42ee217caa686d141ee8 + uses: rtCamp/action-slack-notify@12e36fc18b0689399306c2e0b3e0f2978b7f1ee7 + env: + SLACK_CHANNEL: example-channel + SLACK_COLOR: ${{ job.status }} + SLACK_TITLE: '${{ github.event.repository.name }} v${{ steps.get-version-number-and-issue-url.outputs.version-number }} QA NEEDED' + SLACK_MESSAGE: '${{ steps.get-version-number-and-issue-url.outputs.issue-url }}' + SLACK_WEBHOOK: ${{ inputs.slack-webhook }} + MSG_MINIMAL: true +``` diff --git a/.github/actions/get-version-number-and-issue-url-v1/action.yml b/.github/actions/get-version-number-and-issue-url-v1/action.yml new file mode 100644 index 00000000..c8bb0035 --- /dev/null +++ b/.github/actions/get-version-number-and-issue-url-v1/action.yml @@ -0,0 +1,34 @@ +name: get-version-number-and-issue-url +description: 'A small GitHub Action to get the version number and issue URL for a release candidate' + +outputs: + version-number: + description: 'The version number for the release candidate' + value: ${{ steps.get_version_number.outputs.version-number }} + issue-url: + description: 'The issue URL for the release candidate' + value: ${{ steps.get_issue_url.outputs.issue-url }} + +runs: + using: 'composite' + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + # Fetch all history + fetch-depth: 0 + + - name: Get release-candidate issue URL + id: get_issue_url + shell: bash + run: | + echo "issue-url=$(gh issue list --repo ${{ github.repository }} --label release --state open --json url --jq '.[0].url')" >> $GITHUB_OUTPUT + + - name: Get release-candidate version number + id: get_version_number + shell: bash + run: | + pullRequestID=$(gh pr list --repo ${{ github.repository }} --json number -s merged --base release --jq '.[0].number') + + # Get the version number from the pull request title e.g. 1.33.7 + echo "version-number=$(gh pr view $pullRequestID --repo ${{ github.repository }} --json title --jq '.title' | grep grep -E -o '\d+.\d+.\d+' | awk '{print $NF}')" >> $GITHUB_OUTPUT