-
Notifications
You must be signed in to change notification settings - Fork 212
163 lines (136 loc) · 5.91 KB
/
nightly_release.yml
File metadata and controls
163 lines (136 loc) · 5.91 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
name: SalesforceCommerceCloud/pwa-kit/nightly_release
on:
workflow_dispatch:
schedule:
# Run weekdays at 12am (PST) - cron uses UTC times
- cron: "0 8 * * 1-5"
jobs:
create_nightly_release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get Timestamp
run: |-
echo "release_timestamp=$(date +'%Y%m%d%H%M%S')" >> "$GITHUB_ENV"
- name: Get monorepo version
run: |-
version=`jq -r ".version" package.json | cut -d "-" -f 1`
echo "monorepo_version_base=$version" >> "$GITHUB_ENV"
version_major=`echo "$version" | cut -d "." -f 1`
echo "monorepo_version_major=$version_major" >> "$GITHUB_ENV"
- name: Get nightly version
run: echo "nightly_version=${{ env.monorepo_version_base }}-nightly-${{ env.release_timestamp }}" >> "$GITHUB_ENV"
- name: Get retail-react-app version
run: |-
version=`jq -r ".version" packages/template-retail-react-app/package.json | cut -d "-" -f 1`
echo "retail_app_version_base=$version" >> "$GITHUB_ENV"
- name: Get commerce-sdk-react version
run: |-
version=`jq -r ".version" packages/commerce-sdk-react/package.json | cut -d "-" -f 1`
echo "commerce_sdk_react_version_base=$version" >> "$GITHUB_ENV"
- name: Get pwa-kit-mcp version
run: |-
version=`jq -r ".version" packages/pwa-kit-mcp/package.json | cut -d "-" -f 1`
echo "pwa_kit_mcp_version_base=$version" >> "$GITHUB_ENV"
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 24
cache: npm
- name: Install Monorepo Dependencies
run: |-
# Install node dependencies
node ./scripts/gtime.js monorepo_install npm ci
- name: Update identity in git config
run: |-
git config --global user.name ${{ secrets.GIT_CONFIG_USERNAME }}
git config --global user.email ${{ secrets.GIT_CONFIG_EMAIL }}
- name: Create Release Branch
run: |-
git pull
git switch develop
git switch nightly-releases || git switch -c nightly-releases
# Pull all changes from develop and keep changes from develop in case of merge-conflicts
- name: Pull latest changes from develop
run: |-
git switch develop
git merge -s ours nightly-releases
git switch nightly-releases
git merge develop
- name: Bump version (monorepo)
run: |-
npm run bump-version -- "${{ env.nightly_version }}"
- name: Bump version (retail-react-app)
run: |-
npm run bump-version:retail-react-app -- "${{ env.retail_app_version_base }}-nightly-${{ env.release_timestamp }}"
- name: Bump version (commerce-sdk-react)
run: |-
npm run bump-version:commerce-sdk-react -- "${{ env.commerce_sdk_react_version_base }}-nightly-${{ env.release_timestamp }}"
- name: Bump version (pwa-kit-mcp)
run: |-
npm run bump-version:mcp -- "${{ env.pwa_kit_mcp_version_base }}-nightly-${{ env.release_timestamp }}"
- name: Push version changes to origin
run: |-
git commit -am "Release ${{ env.nightly_version }}"
git push --set-upstream origin nightly-releases
- name: Check Repository Clean
uses: "./.github/actions/check_clean"
- name: Publish to NPM
uses: "./.github/actions/publish_to_npm"
with:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
- name: Create git tag
run: |-
git tag v${{ env.nightly_version }}
git push origin --tags
- name: Send GitHub Action data to Slack workflow (Generated)
id: slack-success
uses: slackapi/slack-github-action@v1.23.0
with:
payload: |
{
"message": "✅ Successfully released PWA Kit v${{ env.nightly_version }}"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
- name: Send GitHub Action data to Slack workflow (Generated)
id: slack-failure
if: ${{ failure() }}
uses: slackapi/slack-github-action@v1.23.0
with:
payload: |
{
"message": "❌ Failed to release PWA Kit v${{ env.monorepo_version_base }}-nightly-${{ env.release_timestamp }} (${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
- name: Check NPM Token Expiry
if: always()
run: |
LAST_ROTATION="${{ secrets.NPM_TOKEN_LAST_ROTATION_DATE }}"
if [ -z "$LAST_ROTATION" ]; then
echo "NPM_TOKEN_LAST_ROTATION_DATE secret not set, skipping expiry check"
exit 0
fi
CURRENT_DATE=$(date +%s)
EXPIRY_DATE=$(( $LAST_ROTATION + 7776000 )) # 90 days in seconds (90 * 24 * 60 * 60)
DAYS_LEFT=$(( ($EXPIRY_DATE - $CURRENT_DATE) / 86400 ))
echo "NPM Token last rotated: $(date -d @$LAST_ROTATION +'%Y-%m-%d')"
echo "Days until expiry: $DAYS_LEFT"
echo "days_left=$DAYS_LEFT" >> "$GITHUB_ENV"
echo "should_notify=$( [ $DAYS_LEFT -le 10 ] && echo 'true' || echo 'false' )" >> "$GITHUB_ENV"
- name: Send Token Expiry Warning to Slack
if: always() && env.should_notify == 'true'
uses: slackapi/slack-github-action@v1.23.0
with:
payload: |
{
"message": "⚠️ NPM Token expiring soon! Only ${{ env.days_left }} days remaining. Please rotate the token using the instructions in this doc: ${{ secrets.PWA_KIT_RELEASE_DOC_LINK }}"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}