-
Notifications
You must be signed in to change notification settings - Fork 3
164 lines (149 loc) · 5.17 KB
/
publish.yml
File metadata and controls
164 lines (149 loc) · 5.17 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
name: Publish
on:
push:
branches:
- main
workflow_dispatch:
inputs:
snapshot_tag:
description: 'changesets snapshot tag (beta/canary)'
required: false
default: 'beta'
type: string
npm_tag:
description: 'npm dist-tag for publishing snapshot'
required: false
default: 'beta'
type: string
npm_access:
description: 'access level for publishing snapshot to npm'
required: false
default: 'public'
type: choice
options:
- public
- restricted
env:
NX_CLOUD_ENCRYPTION_KEY: ${{ secrets.NX_CLOUD_ENCRYPTION_KEY }}
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
SLACK_WEBHOOK_URL_BETA: ${{ secrets.SLACK_WEBHOOK_URL_BETA }}
PNPM_CACHE_FOLDER: .pnpm-store
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
CI: true
jobs:
publish-or-pr:
if: github.event_name == 'push'
permissions:
contents: write
issues: write
pull-requests: write
id-token: write
runs-on: ubuntu-latest
env:
LEFTHOOK: 0
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GH_TOKEN }}
- name: Setup Project
uses: ./.github/actions/setup
with:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: publish
uses: changesets/action@v1
id: changesets
with:
publish: pnpm ci:release
version: pnpm ci:version
title: Release PR
branch: main
commit: 'chore: version-packages'
setupGitUser: true
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Publish Release Steps
if: steps.changesets.outputs.published == 'true'
uses: ./.github/actions/publish-release
with:
publishedPackages: ${{ steps.changesets.outputs.publishedPackages }}
slackWebhook: ${{ secrets.SLACK_WEBHOOK_URL }}
- name: Publish Beta Steps
if: steps.changesets.outputs.published == 'false'
uses: ./.github/actions/publish-beta
- name: Calculate baseline bundle sizes
run: |
chmod +x ./scripts/bundle-sizes.sh
rm -f previous_sizes.json
echo "📊 Calculating fresh baseline bundle sizes for main branch"
./scripts/bundle-sizes.sh
echo "✅ Baseline bundle sizes calculated"
cat previous_sizes.json
- name: Upload baseline bundle sizes
uses: actions/upload-artifact@v5
with:
name: bundle-size-baseline
path: previous_sizes.json
retention-days: 30
snapshot:
# Guard against publishing snapshots from the protected release branch.
if: >-
${{
github.event_name == 'workflow_dispatch' &&
github.ref != 'refs/heads/changeset-release/main'
}}
name: Publish Snapshots
permissions:
contents: write
id-token: write
issues: write
pull-requests: write
runs-on: ubuntu-latest
env:
LEFTHOOK: 0
steps:
- name: Branch name
run: |
echo "Checking out branch: ${{ github.ref_name }}"
# Checkout the branch selected when triggering the workflow
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GH_TOKEN }}
- name: Setup Project
uses: ./.github/actions/setup
with:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Version Packages for snapshot
run: pnpm changeset version --snapshot ${{ inputs.snapshot_tag }}
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Publish packages snapshot with npm_tag
id: npmpublish
run: pnpm publish -r --tag ${{ inputs.npm_tag }} --no-git-checks --access ${{ inputs.npm_access }}
- name: Format published packages for Slack
if: steps.npmpublish.outcome == 'success'
id: format-packages
env:
NPM_TAG: ${{ inputs.npm_tag }}
SNAPSHOT_TAG: ${{ inputs.snapshot_tag }}
run: |
FORMATTED=$(jq -rs --arg tag "$SNAPSHOT_TAG" '[.[] | select(.version | contains($tag))] | .[] | ":package: *\(.name)* `\(.version)`"' packages/*/package.json packages/sdk-effects/*/package.json 2>/dev/null | sort -u)
PAYLOAD=$(jq -n --arg packages "$FORMATTED" --arg npmTag "$NPM_TAG" '{"npmTag": $npmTag, "publishedPackages": $packages}')
echo "payload<<EOF" >> $GITHUB_OUTPUT
echo "$PAYLOAD" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Send GitHub Action data to a Slack workflow
if: steps.npmpublish.outcome == 'success'
id: slack-notify-beta
continue-on-error: true
uses: slackapi/slack-github-action@v2.1.1
with:
webhook: ${{ env.SLACK_WEBHOOK_URL_BETA }}
webhook-type: webhook-trigger
payload: ${{ steps.format-packages.outputs.payload }}
- name: Warn if Slack notification failed
if: steps.slack-notify-beta.outcome == 'failure'
run: |
echo "::warning::Slack beta notification failed. Check the webhook URL and payload format."