-
Notifications
You must be signed in to change notification settings - Fork 86
148 lines (130 loc) · 5.12 KB
/
release.yml
File metadata and controls
148 lines (130 loc) · 5.12 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
name: Release
on:
workflow_dispatch:
inputs:
version_type:
description: "The type of version bump"
required: true
type: choice
default: "patch"
options:
- patch
- minor
- explicit
- test
version:
description: "The explicit version to use (for 'explicit' type)"
required: false
type: string
create_gh_release:
description: "If false, skips creating a GitHub release."
required: false
type: boolean
default: true
skip_smoke_tests:
description: "If true, bypasses the smoke testing step. Use with caution."
required: false
type: boolean
default: false
permissions:
id-token: write
contents: write
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
jobs:
release:
if: github.ref == 'refs/heads/main' || github.event.inputs.version_type == 'test'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
# We need to fetch all history for semver to work correctly and to push changes.
fetch-depth: 0
# This token should have write permissions to the repository.
# It's recommended to use a dedicated bot account's PAT.
# The secret should be named GH_TOKEN_FOR_RELEASES
token: ${{ secrets.GH_TOKEN_FOR_RELEASES }}
- name: Set up Git user
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Enable Corepack
run: corepack enable
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24.14.0
cache: "pnpm"
- name: Update npm
run: npm install -g npm@latest
- name: Install dependencies
run: pnpm install
- name: Setup .npmrc for publishing
working-directory: sdk
run: |
echo "registry=https://registry.npmjs.org/" >> .npmrc
- name: Run release script
id: release_script
working-directory: sdk
run: |
COMMAND="./scripts/release.sh ${{ github.event.inputs.version_type }}"
if [[ "${{ github.event.inputs.version_type }}" == "explicit" ]]; then
if [[ -z "${{ github.event.inputs.version }}" ]]; then
echo "::error::The 'version' input is required when 'version_type' is 'explicit'."
exit 1
fi
COMMAND="$COMMAND --version ${{ github.event.inputs.version }}"
elif [[ -n "${{ github.event.inputs.version }}" ]]; then
echo "::error::The 'version' input can only be used when 'version_type' is 'explicit'."
exit 1
fi
if [[ "${{ github.event.inputs.skip_smoke_tests }}" == "true" ]]; then
COMMAND="$COMMAND --skip-smoke-tests"
fi
echo "Running command: $COMMAND"
eval $COMMAND
- name: Create GitHub Release
if: success() && github.event.inputs.create_gh_release == 'true'
env:
GH_TOKEN: ${{ secrets.GH_TOKEN_FOR_RELEASES }}
run: |
FLAGS="--generate-notes"
VERSION_TYPE="${{ github.event.inputs.version_type }}"
VERSION="${{ github.event.inputs.version }}"
if [[ "$VERSION_TYPE" == "patch" || "$VERSION_TYPE" == "minor" || "$VERSION_TYPE" == "beta" ]]; then
FLAGS="$FLAGS --latest"
elif [[ "$VERSION_TYPE" == "explicit" ]]; then
# For explicit versions, we check the version string to determine if it's a pre-release
if [[ "$VERSION" == *"-beta."* ]]; then
FLAGS="$FLAGS --latest"
elif [[ "$VERSION" == *"-"* ]]; then
FLAGS="$FLAGS --prerelease"
else
FLAGS="$FLAGS --latest"
fi
elif [[ "$VERSION_TYPE" == "test" ]]; then
FLAGS="$FLAGS --prerelease"
fi
echo "Creating GitHub release for tag ${{ env.TAG_NAME }} with flags: $FLAGS"
gh release create ${{ env.TAG_NAME }} $FLAGS
- name: Prune node_modules for artifact upload
if: failure() && steps.release_script.outputs.project-dir
run: |
echo "Pruning node_modules to reduce artifact size..."
find ${{ steps.release_script.outputs.project-dir }}/node_modules -mindepth 1 -maxdepth 1 -not -name "rwsdk" -exec rm -rf {} +
echo "Pruning complete."
- name: Upload logs on failure
if: failure() && steps.release_script.outputs.project-dir
uses: actions/upload-artifact@v7
with:
name: smoke-test-failure-logs
path: ${{ steps.release_script.outputs.project-dir }}
- name: Upload smoke test artifacts
if: always() && steps.release_script.outputs.project-dir
uses: actions/upload-artifact@v7
with:
name: release-smoke-test-artifacts
path: ${{ steps.release_script.outputs.project-dir }}/artifacts
retention-days: 7