-
-
Notifications
You must be signed in to change notification settings - Fork 7
107 lines (101 loc) · 3.72 KB
/
Copy pathpublish-release.yml
File metadata and controls
107 lines (101 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
name: Publish Release
on:
workflow_call:
inputs:
slack-icon-url:
required: false
type: string
default: 'https://raw.githubusercontent.com/MetaMask/action-npm-publish/main/robo.png'
slack-subteam:
required: false
type: string
default: S042S7RE4AE # @metamask-npm-publishers
slack-username:
required: false
type: string
default: 'MetaMask bot'
secrets:
SLACK_WEBHOOK_URL:
required: true
permissions:
contents: read
jobs:
announce-release:
name: Announce release
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
persist-credentials: false
- id: name-hash
name: Get Slack name and hash
shell: bash
if: inputs.slack-subteam != ''
run: |
NAME_VERSION_TEXT=$(jq --raw-output '.name + "@" + .version' package.json )
NAME_VERSION_TEXT_STRIPPED="${NAME_VERSION_TEXT#@}"
echo "NAME_VERSION=$NAME_VERSION_TEXT_STRIPPED" >> "$GITHUB_OUTPUT"
- id: final-text
name: Get Slack final text
shell: bash
if: inputs.slack-subteam != ''
run: |
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>"
SUBTEAM_TEXT="${INPUTS_SLACK_SUBTEAM}"
FINAL_TEXT="$DEFAULT_TEXT"
if [[ ! "$SUBTEAM_TEXT" == "" ]]; then
FINAL_TEXT="<!subteam^$SUBTEAM_TEXT> $DEFAULT_TEXT"
fi
echo "FINAL_TEXT=$FINAL_TEXT" >> "$GITHUB_OUTPUT"
env:
STEPS_NAME_HASH_OUTPUTS_NAME_VERSION: ${{ steps.name-hash.outputs.NAME_VERSION }}
INPUTS_SLACK_SUBTEAM: ${{ inputs.slack-subteam }}
- name: Post to a Slack channel
if: inputs.slack-subteam != ''
uses: slackapi/slack-github-action@45a88b9581bfab2566dc881e2cd66d334e621e2c # v3.0.3
with:
webhook-type: incoming-webhook
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
payload: |
{
"text": "${{ steps.final-text.outputs.FINAL_TEXT }}",
"icon_url": "${{ inputs.slack-icon-url }}",
"username": "${{ inputs.slack-username }}"
}
continue-on-error: true
publish-release:
name: Publish release
environment: action-publish
needs: announce-release
permissions:
contents: read
id-token: write
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
# This is to guarantee that the most recent tag is fetched, which we
# need for updating the shorthand major version tag.
fetch-depth: 0
ref: ${{ github.sha }}
persist-credentials: false
- name: Get token
id: get-token
uses: MetaMask/github-tools/.github/actions/get-token@v1
with:
token-exchange-url: ${{ vars.TOKEN_EXCHANGE_URL }}
permissions: |
contents: write
- name: Publish release
uses: MetaMask/action-publish-release@b842808ef45c9e3b085060b94b1d4a1fac00aa81 # v3.2.2
id: publish-release
env:
GITHUB_TOKEN: ${{ steps.get-token.outputs.token }}
- name: Update shorthand major version tag
uses: MetaMask/github-tools/.github/actions/update-major-version-tag@v1
with:
release-version: ${{ steps.publish-release.outputs.release-version }}
github-token: ${{ steps.get-token.outputs.token }}