|
| 1 | +name: Publish Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + slack-icon-url: |
| 7 | + required: false |
| 8 | + type: string |
| 9 | + default: 'https://raw.githubusercontent.com/MetaMask/action-npm-publish/main/robo.png' |
| 10 | + slack-subteam: |
| 11 | + required: false |
| 12 | + type: string |
| 13 | + default: S042S7RE4AE # @metamask-npm-publishers |
| 14 | + slack-username: |
| 15 | + required: false |
| 16 | + type: string |
| 17 | + default: 'MetaMask bot' |
| 18 | + secrets: |
| 19 | + SLACK_WEBHOOK_URL: |
| 20 | + required: true |
| 21 | + |
| 22 | +jobs: |
| 23 | + announce-release: |
| 24 | + name: Announce release |
| 25 | + runs-on: ubuntu-latest |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@v5 |
| 28 | + - id: name-hash |
| 29 | + name: Get Slack name and hash |
| 30 | + shell: bash |
| 31 | + if: inputs.slack-subteam != '' |
| 32 | + run: | |
| 33 | + NAME_VERSION_TEXT=$(jq --raw-output '.name + "@" + .version' package.json ) |
| 34 | + NAME_VERSION_TEXT_STRIPPED="${NAME_VERSION_TEXT#@}" |
| 35 | + echo "NAME_VERSION=$NAME_VERSION_TEXT_STRIPPED" >> "$GITHUB_OUTPUT" |
| 36 | + - id: final-text |
| 37 | + name: Get Slack final text |
| 38 | + shell: bash |
| 39 | + if: inputs.slack-subteam != '' |
| 40 | + run: | |
| 41 | + DEFAULT_TEXT="\`${{ steps.name-hash.outputs.NAME_VERSION }}\` is awaiting deployment :rocket: \n <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/|→ Click here to review deployment>" |
| 42 | + SUBTEAM_TEXT="${{ inputs.slack-subteam }}" |
| 43 | + FINAL_TEXT="$DEFAULT_TEXT" |
| 44 | + if [[ ! "$SUBTEAM_TEXT" == "" ]]; then |
| 45 | + FINAL_TEXT="<!subteam^$SUBTEAM_TEXT> $DEFAULT_TEXT" |
| 46 | + fi |
| 47 | + echo "FINAL_TEXT=$FINAL_TEXT" >> "$GITHUB_OUTPUT" |
| 48 | + - name: Post to a Slack channel |
| 49 | + if: inputs.slack-subteam != '' |
| 50 | + uses: slackapi/slack-github-action@007b2c3c751a190b6f0f040e47ed024deaa72844 |
| 51 | + with: |
| 52 | + payload: | |
| 53 | + { |
| 54 | + "text": "${{ steps.final-text.outputs.FINAL_TEXT }}", |
| 55 | + "icon_url": "${{ inputs.slack-icon-url }}", |
| 56 | + "username": "${{ inputs.slack-username }}" |
| 57 | + } |
| 58 | + env: |
| 59 | + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |
| 60 | + SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK |
| 61 | + continue-on-error: true |
| 62 | + |
| 63 | + publish-release: |
| 64 | + name: Publish release |
| 65 | + environment: npm-publish |
| 66 | + needs: announce-release |
| 67 | + permissions: |
| 68 | + contents: write |
| 69 | + runs-on: ubuntu-latest |
| 70 | + steps: |
| 71 | + - name: Checkout repository |
| 72 | + uses: actions/checkout@v5 |
| 73 | + with: |
| 74 | + # This is to guarantee that the most recent tag is fetched, which we |
| 75 | + # need for updating the shorthand major version tag. |
| 76 | + fetch-depth: 0 |
| 77 | + ref: ${{ github.sha }} |
| 78 | + - name: Publish release |
| 79 | + uses: MetaMask/action-publish-release@v3 |
| 80 | + id: publish-release |
| 81 | + env: |
| 82 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 83 | + - name: Update shorthand major version tag |
| 84 | + run: | |
| 85 | + ./.github/workflows/scripts/update-major-version-tag.sh \ |
| 86 | + ${{ steps.publish-release.outputs.release-version }} |
0 commit comments