-
Notifications
You must be signed in to change notification settings - Fork 22
165 lines (140 loc) · 5.02 KB
/
release.yml
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
name: Release
on:
schedule:
- cron: "0 5 * * 1,4" # at 05:00 on monday,thursday
workflow_dispatch:
jobs:
tests:
name: Tests
uses: ./.github/workflows/tests.yml
secrets: inherit
visual-tests:
name: Visual Tests
uses: ./.github/workflows/tests-visual.yml
secrets: inherit
publish:
name: Publish Packages
needs: [tests, visual-tests]
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CHECKOUT_REF: ${{ github.event.client_payload.ref }}
RELEASE_TYPE: ${{ github.event.client_payload.type }}
NPM_CONFIG_PROVENANCE: true
outputs:
NEW_VERSION: ${{ steps.version.outputs.NEW_VERSION }}
permissions:
contents: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Pulls all commits (needed for semantic release to correctly version)
# See https://github.com/semantic-release/semantic-release/issues/1526
fetch-depth: "0"
fetch-tags: true
- name: Publish Setup
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Install Dependencies
uses: ./.github/actions/install-dependencies
- name: Publish to NPM
id: publish-npm
env:
NODE_AUTH_TOKEN: ${{secrets.HV_NPM_AUTOMATION_TOKEN}}
run: |
VERSION=v$(npm pkg get version -ws | sed -n 's/.*uikit-react-core": "\(.*\)".*/\1/p')
echo "CURRENT_VERSION=$VERSION" >> "$GITHUB_ENV"
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
npm run publish 2>&1 | tee publish_logs.txt
- name: Check if packages were updated
run: |
if grep -q "lerna success published" publish_logs.txt; then
echo "New packages were published"
elif grep -q "lerna Command failed" publish_logs.txt; then
echo "lerna Command failed"
exit 1
else
echo "No packages were updated"
exit 1
fi
- name: Set NEW_VERSION
id: version
# Outputs the NEW_VERSION if there is one, or empty otherwise
run: |
VERSION=v$(npm pkg get version -ws | sed -n 's/.*uikit-react-core": "\(.*\)".*/\1/p')
echo "NEW_VERSION=$( [ "$CURRENT_VERSION" = "$VERSION" ] && echo "" || echo "$VERSION" )" >> "$GITHUB_OUTPUT"
- name: Tag Release
if: steps.version.outputs.NEW_VERSION
env:
VERSION: ${{steps.version.outputs.NEW_VERSION}}
run: |
git tag -a $VERSION -m "Version $VERSION"
git push origin $VERSION
- name: Create GitHub Release
if: steps.version.outputs.NEW_VERSION
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{steps.version.outputs.NEW_VERSION}}
run: npx [email protected] --from $CURRENT_VERSION --to $VERSION
publish-documentation:
name: Publish Documentation
needs: [publish]
uses: ./.github/workflows/documentation.yml
secrets: inherit
with:
publish-folder: ${{ github.ref_name }}
security-scans:
name: Security Scans
needs: [publish]
uses: ./.github/workflows/security.yml
secrets: inherit
notify-release:
name: Notify release
runs-on: ubuntu-latest
needs: [publish]
if: needs.publish.outputs.NEW_VERSION
env:
DOCUMENTATION_URL: https://${{ github.repository_owner }}.github.io/uikit/${{ github.ref_name }}/
VERSION: ${{ needs.publish.outputs.NEW_VERSION }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get Releases Commit Message
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const branch = await github.repos.getBranch({
owner: context.repo.owner,
repo: context.repo.repo,
branch: "${{ github.ref_name }}"
})
const commitMessage = branch.data.commit.commit.message
const slackMessage = commitMessage.replace('chore(release): publish', '')
.replace(/\n/g, "\\n")
.replace(/\r/g, "\\r")
.replace(/\t/g, "\\t")
.replace(/\f/g, "\\f")
core.exportVariable("SLACK_MESSAGE", slackMessage)
- name: Notify release
uses: hbfernandes/[email protected]
if: success()
env:
SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}
with:
args: |
{
"channel": "ui-kit",
"attachments": [
{
"mrkdwn_in": ["text"],
"author_name": "New UI-Kit Release is available",
"title": "https://github.com/${{github.repository}}/releases/${{env.VERSION}}",
"text": "${{env.SLACK_MESSAGE}}",
"footer": "${{env.DOCUMENTATION_URL}}"
}
]
}