-
Notifications
You must be signed in to change notification settings - Fork 22
144 lines (125 loc) · 4.47 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
name: Release
on:
repository_dispatch:
types: [release]
workflow_dispatch:
jobs:
publish:
name: Publish
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CHECKOUT_REF: ${{ github.event.client_payload.ref }}
RELEASE_TYPE: ${{ github.event.client_payload.type }}
outputs:
published: ${{ steps.check-updates.outputs.published }}
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"
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 16
- name: Fetch git tags
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- 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: Publish to NPM
id: publish-npm
env:
NODE_AUTH_TOKEN: ${{secrets.HV_NPM_AUTOMATION_TOKEN}}
run: |
npm ci --include=dev
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
if [[ "${{ github.ref_name }}" == "master" ]]; then
npm run publish:release 2>&1 | tee publish_logs.txt
elif [[ "${{ github.ref_name }}" == "next"* ]]; then
npm run publish:next 2>&1 | tee publish_logs.txt
else
echo "Invalid event type: ${{ github.ref_name }}"
exit 1
fi
- name: Check if packages were updated
id: check-updates
run: |
if grep -q "lerna success published" publish_logs.txt; then
echo "New packages were published"
echo "published=true" >> "$GITHUB_OUTPUT"
elif grep -q "lerna Command failed" publish_logs.txt; then
echo "lerna Command failed"
exit 1
else
echo "No packages were updated"
echo "published=false" >> "$GITHUB_OUTPUT"
fi
publish-artifacts:
name: Publish Artifacts
needs: [publish]
if: needs.publish.outputs.published == 'true'
uses: ./.github/workflows/documentation.yml
secrets: inherit
with:
publish-folder: ${{ github.ref_name }}
notify-release:
name: Notify release
runs-on: ubuntu-latest
needs: [publish-artifacts]
env:
DOCUMENTATION_URL: https://${{ github.repository_owner }}.github.io/uikit/${{ github.ref_name }}/
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 artifacts are available",
"title": "More details https://github.com/${{github.repository}}/releases",
"text": "${{env.SLACK_MESSAGE}}",
"footer": "${{env.DOCUMENTATION_URL}}"
}
]
}
security-scans:
name: Security Scans
needs: [publish-artifacts]
runs-on: ubuntu-latest
steps:
- name: Trigger Security Scans
# repo scope personal token is required to generate a dispatch event
run: |
curl -X POST \
https://api.github.com/repos/${{ github.repository }}/dispatches \
-H 'Authorization: token ${{ secrets.GITHUB_TOKEN }}' \
-d '{"event_type": "security"}'