-
Notifications
You must be signed in to change notification settings - Fork 0
113 lines (98 loc) · 3.88 KB
/
release.yml
File metadata and controls
113 lines (98 loc) · 3.88 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
name: Release
on:
workflow_run:
workflows: ["CI"]
types:
- completed
branches:
- main
- "*-[0-9]+.x" # Package maintenance branches (e.g., swarm-wasp-1.x, swarm-2.x)
permissions:
contents: write
pull-requests:
write
# Needed for workflow_run
packages: write
actions: write
id-token: write
jobs:
release:
name: Release
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' && (github.event.workflow_run.head_branch == 'main' || endsWith(github.event.workflow_run.head_branch, '-[0-9]+.x')) }}
env:
RELEASE_COMMIT_MESSAGE: "chore: version packages"
RELEASE_PR_TITLE: "Release Packages"
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.PAT_TOKEN }}
# Checkout the branch to get the latest commit which includes
# any changesets that were committed during the CI workflow
ref: ${{ github.event.workflow_run.head_branch }}
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24
registry-url: "https://registry.npmjs.org"
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build packages
run: pnpm run build
- name: Set Git user name and email
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Fetch latest commits
run: |
BRANCH="${{ github.event.workflow_run.head_branch }}"
git fetch origin "$BRANCH"
git checkout "$BRANCH"
echo "Latest commit: $(git log -1 --oneline)"
- name: Determine release tag
id: release-tag
run: |
BRANCH="${{ github.event.workflow_run.head_branch }}"
if [[ "$BRANCH" =~ ^(.+)-([0-9]+)\.x$ ]]; then
# Maintenance branch: <package>-N.x
MAJOR="${BASH_REMATCH[2]}"
echo "tag=v${MAJOR}" >> $GITHUB_OUTPUT
echo "is_maintenance=true" >> $GITHUB_OUTPUT
echo "pr_suffix= [${BRANCH}]" >> $GITHUB_OUTPUT
echo "Publishing to 'v${MAJOR}' tag (maintenance branch: ${BRANCH})"
else
# Main branch or other
echo "tag=" >> $GITHUB_OUTPUT
echo "is_maintenance=false" >> $GITHUB_OUTPUT
echo "pr_suffix=" >> $GITHUB_OUTPUT
echo "Publishing to 'latest' tag"
fi
- name: Create Release PR or Publish to NPM
id: changesets
uses: changesets/action@v1
with:
commit: "${{ env.RELEASE_COMMIT_MESSAGE }}${{ steps.release-tag.outputs.pr_suffix }}"
title: "${{ env.RELEASE_PR_TITLE }}${{ steps.release-tag.outputs.pr_suffix }}"
version: pnpm changeset:version
publish: pnpm release ${{ steps.release-tag.outputs.tag != '' && format('--tag {0}', steps.release-tag.outputs.tag) || '' }}
createGithubReleases: true
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
NODE_AUTH_TOKEN: ""
- name: Format Release PR
if: ${{ steps.changesets.outputs.pullRequestNumber != '' }}
env:
PR_NUMBER: ${{ steps.changesets.outputs.pullRequestNumber }}
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
run: node .github/scripts/format-release-pr.js
- name: Update Subrepo Dependencies
if: steps.changesets.outputs.published == 'true' && steps.release-tag.outputs.is_maintenance == 'false'
run: node .github/scripts/update-subrepo-deps.js
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
PUBLISHED_PACKAGES: ${{ steps.changesets.outputs.publishedPackages }}