-
Notifications
You must be signed in to change notification settings - Fork 28
184 lines (163 loc) · 7.51 KB
/
release.yaml
File metadata and controls
184 lines (163 loc) · 7.51 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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
name: Release
on:
workflow_run:
workflows: ['CI']
types:
- completed
branches:
- main
- canary
workflow_dispatch:
jobs:
release:
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
actions: read
packages: write
steps:
- name: Retrieve Secrets from Vault
id: vault
uses: hashicorp/vault-action@v3.4.0
with:
url: ${{ secrets.VAULT_URL }}
role: ${{ github.event.repository.name }}-github-action
method: jwt
path: github-actions
exportEnv: false
secrets: |
secret/data/github/github_packages_write GITHUB_PACKAGES_WRITE_TOKEN | GITHUB_PACKAGES_WRITE_TOKEN;
github/token/${{ github.event.repository.name }}-semantic-release token | GITHUB_TOKEN ;
secret/data/github/automation-app-user GH_USER_NAME | GIT_COMMITTER_NAME ;
secret/data/github/automation-app-user GH_USER_EMAIL | GIT_COMMITTER_EMAIL ;
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ github.event.workflow_run.head_branch || github.ref }}
token: ${{ steps.vault.outputs.GITHUB_TOKEN }}
- name: Get Automation Bot User ID
id: get-user-id
run: |
USER_ID=$(gh api "/users/contentful-automation[bot]" --jq .id)
if [ -z "$USER_ID" ] || [ "$USER_ID" = "null" ]; then
echo "Error: Failed to retrieve bot user ID"
exit 1
fi
echo "user-id=$USER_ID" >> "$GITHUB_OUTPUT"
env:
GITHUB_TOKEN: ${{ steps.vault.outputs.GITHUB_TOKEN }}
- name: Setting up Git User Credentials
run: |
git config --global user.name 'contentful-automation[bot]'
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+contentful-automation[bot]@users.noreply.github.com'
- name: Setup npmrc for publishing
run: |
echo "//npm.pkg.github.com/:_authToken=${{ steps.vault.outputs.GITHUB_PACKAGES_WRITE_TOKEN }}" > .npmrc
echo "@contentful:registry=https://npm.pkg.github.com" >> .npmrc
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '22'
cache: 'npm'
registry-url: 'https://registry.npmjs.org'
- name: Install latest npm
run: npm install -g npm@latest
- name: Install dependencies
run: npm ci && npm run bootstrap
- name: Build
run: npm run build
- name: Version (main branch)
if: (github.event.workflow_run.head_branch || github.ref_name) == 'main'
run: npm run version
env:
GITHUB_TOKEN: ${{ steps.vault.outputs.GITHUB_TOKEN }}
GH_TOKEN: ${{ steps.vault.outputs.GITHUB_TOKEN }}
NPM_TOKEN: ${{ steps.vault.outputs.GITHUB_PACKAGES_WRITE_TOKEN }}
NODE_AUTH_TOKEN: ${{ steps.vault.outputs.GITHUB_PACKAGES_WRITE_TOKEN }}
GIT_AUTHOR_NAME: ${{ steps.vault.outputs.GIT_COMMITTER_NAME }}
GIT_AUTHOR_EMAIL: ${{ steps.vault.outputs.GIT_COMMITTER_EMAIL }}
GIT_COMMITTER_NAME: ${{ steps.vault.outputs.GIT_COMMITTER_NAME }}
GIT_COMMITTER_EMAIL: ${{ steps.vault.outputs.GIT_COMMITTER_EMAIL }}
- name: Publish (main branch)
if: (github.event.workflow_run.head_branch || github.ref_name) == 'main'
run: npm run publish-packages
env:
GITHUB_TOKEN: ${{ steps.vault.outputs.GITHUB_TOKEN }}
GH_TOKEN: ${{ steps.vault.outputs.GITHUB_TOKEN }}
NPM_TOKEN: ${{ steps.vault.outputs.GITHUB_PACKAGES_WRITE_TOKEN }}
NODE_AUTH_TOKEN: ${{ steps.vault.outputs.GITHUB_PACKAGES_WRITE_TOKEN }}
GIT_AUTHOR_NAME: ${{ steps.vault.outputs.GIT_COMMITTER_NAME }}
GIT_AUTHOR_EMAIL: ${{ steps.vault.outputs.GIT_COMMITTER_EMAIL }}
GIT_COMMITTER_NAME: ${{ steps.vault.outputs.GIT_COMMITTER_NAME }}
GIT_COMMITTER_EMAIL: ${{ steps.vault.outputs.GIT_COMMITTER_EMAIL }}
- name: Version (canary branch)
if: (github.event.workflow_run.head_branch || github.ref_name) == 'canary'
run: npm run version:canary
env:
GITHUB_TOKEN: ${{ steps.vault.outputs.GITHUB_TOKEN }}
GH_TOKEN: ${{ steps.vault.outputs.GITHUB_TOKEN }}
NPM_TOKEN: ${{ steps.vault.outputs.GITHUB_PACKAGES_WRITE_TOKEN }}
NODE_AUTH_TOKEN: ${{ steps.vault.outputs.GITHUB_PACKAGES_WRITE_TOKEN }}
GIT_AUTHOR_NAME: ${{ steps.vault.outputs.GIT_COMMITTER_NAME }}
GIT_AUTHOR_EMAIL: ${{ steps.vault.outputs.GIT_COMMITTER_EMAIL }}
GIT_COMMITTER_NAME: ${{ steps.vault.outputs.GIT_COMMITTER_NAME }}
GIT_COMMITTER_EMAIL: ${{ steps.vault.outputs.GIT_COMMITTER_EMAIL }}
- name: Publish (canary branch)
if: (github.event.workflow_run.head_branch || github.ref_name) == 'canary'
run: npm run publish-packages:canary
env:
GITHUB_TOKEN: ${{ steps.vault.outputs.GITHUB_TOKEN }}
GH_TOKEN: ${{ steps.vault.outputs.GITHUB_TOKEN }}
NPM_TOKEN: ${{ steps.vault.outputs.GITHUB_PACKAGES_WRITE_TOKEN }}
NODE_AUTH_TOKEN: ${{ steps.vault.outputs.GITHUB_PACKAGES_WRITE_TOKEN }}
GIT_AUTHOR_NAME: ${{ steps.vault.outputs.GIT_COMMITTER_NAME }}
GIT_AUTHOR_EMAIL: ${{ steps.vault.outputs.GIT_COMMITTER_EMAIL }}
GIT_COMMITTER_NAME: ${{ steps.vault.outputs.GIT_COMMITTER_NAME }}
GIT_COMMITTER_EMAIL: ${{ steps.vault.outputs.GIT_COMMITTER_EMAIL }}
- name: Print lerna debug log
if: always()
run: |
if [ -f lerna-debug.log ]; then
echo "=== lerna-debug.log ==="
cat lerna-debug.log
else
echo "No lerna-debug.log found"
fi
- name: Get latest release tag
id: get-tag
run: |
# Fetch latest release, handling 404 when no release exists
RESPONSE=$(gh api repos/${{ github.repository }}/releases/latest 2>&1) || EXIT_CODE=$?
if [ "${EXIT_CODE:-0}" -ne 0 ]; then
echo "No existing release found (API returned error). Skipping tag export."
echo "tag=" >> $GITHUB_OUTPUT
else
TAG=$(echo "$RESPONSE" | jq -r '.tag_name // empty')
if [ -n "$TAG" ]; then
echo "Found latest release tag: $TAG"
echo "tag=$TAG" >> $GITHUB_OUTPUT
else
echo "No tag_name found in API response. Skipping tag export."
echo "tag=" >> $GITHUB_OUTPUT
fi
fi
env:
GITHUB_TOKEN: ${{ steps.vault.outputs.GITHUB_TOKEN }}
- name: Summary
run: |
TAG="${{ steps.get-tag.outputs.tag }}"
if [ -z "$TAG" ]; then
echo "## Release Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "⚠️ **No release was created or found.** This may be expected if lerna determined no release was needed." >> $GITHUB_STEP_SUMMARY
else
VERSION=$(echo "$TAG" | sed 's/^v//')
echo "## Release Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Tag**: $TAG" >> $GITHUB_STEP_SUMMARY
echo "- **Version**: $VERSION" >> $GITHUB_STEP_SUMMARY
echo "- **GitHub Release**: https://github.com/${{ github.repository }}/releases/tag/$TAG" >> $GITHUB_STEP_SUMMARY
fi