-
Notifications
You must be signed in to change notification settings - Fork 1
165 lines (137 loc) · 6.02 KB
/
release.yml
File metadata and controls
165 lines (137 loc) · 6.02 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
name: Release Package
on:
workflow_dispatch:
inputs:
package:
description: 'Package to release'
required: true
type: choice
options:
- core
- dzi
- geometry
- omezarr
- web-components
permissions:
contents: write
packages: write
pull-requests: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9.14.2
- name: Install dependencies
run: pnpm install
- name: Configure Git
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Set the remote URL to use the token for pushing
git remote set-url origin https://x-access-token:${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
- name: Get current version and determine next version
id: version_info
run: |
cd packages/${{ github.event.inputs.package }}
# Get current version
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
# Use git-cliff to determine the next version
TAG_PATTERN="@alleninstitute/vis-${{ github.event.inputs.package }}@*"
NEXT_VERSION=$(npx git-cliff --tag-pattern "$TAG_PATTERN" --bumped-version)
# Extract just the version number (remove the tag prefix)
NEXT_VERSION=$(echo "$NEXT_VERSION" | sed 's/.*@//')
echo "next_version=$NEXT_VERSION" >> $GITHUB_OUTPUT
echo "Current version: $CURRENT_VERSION"
echo "Next version: $NEXT_VERSION"
- name: Update version number and create initial tag
run: |
cd packages/${{ github.event.inputs.package }}
# npm version creates a commit and a tag for us
npm version ${{ steps.version_info.outputs.next_version }} --no-git-tag-version=false
- name: Generate changelog
run: |
cd packages/${{ github.event.inputs.package }}
pnpm run changelog
- name: Amend commit with changelog
run: |
cd packages/${{ github.event.inputs.package }}
git add changelog.md
git commit --amend --no-edit
- name: Delete the tag created by npm version and create new one
id: create_tag
run: |
cd packages/${{ github.event.inputs.package }}
TAG_NAME="@alleninstitute/vis-${{ github.event.inputs.package }}@${{ steps.version_info.outputs.next_version }}"
# Delete the tag created by npm version (it would be just the version number)
git tag -d v${{ steps.version_info.outputs.next_version }} || true
# Create a new tag with our naming convention on the amended commit
git tag -a "$TAG_NAME" -m "Release $TAG_NAME"
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
- name: Create release branch and push changes
run: |
BRANCH_NAME="release/${{ github.event.inputs.package }}-v${{ steps.version_info.outputs.next_version }}"
git checkout -b "$BRANCH_NAME"
git push origin "$BRANCH_NAME"
- name: Create Pull Request
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
script: |
const { data: pullRequest } = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `Release ${{ github.event.inputs.package }} v${{ steps.version_info.outputs.next_version }}`,
head: `release/${{ github.event.inputs.package }}-v${{ steps.version_info.outputs.next_version }}`,
base: 'main',
body: `Automated release for @alleninstitute/vis-${{ github.event.inputs.package }} v${{ steps.version_info.outputs.next_version }}\n\nSee [CHANGELOG](./packages/${{ github.event.inputs.package }}/changelog.md) for details.`
});
// Auto-merge if you have that enabled
await github.rest.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pullRequest.number,
merge_method: 'squash'
});
- name: Push tag after merge
run: |
# Wait a moment for the merge to complete
sleep 5
git checkout main
git pull origin main
git push origin ${{ steps.create_tag.outputs.tag_name }}
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.create_tag.outputs.tag_name }}
release_name: "${{ github.event.inputs.package }} v${{ steps.version_info.outputs.next_version }}"
body: |
Release of @alleninstitute/vis-${{ github.event.inputs.package }} v${{ steps.version_info.outputs.next_version }}
See [CHANGELOG](./packages/${{ github.event.inputs.package }}/changelog.md) for details.
draft: false
prerelease: false
- name: Publish to GitHub Packages (if needed)
run: |
cd packages/${{ github.event.inputs.package }}
echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > .npmrc
echo "@alleninstitute:registry=https://npm.pkg.github.com" >> .npmrc
# Build the package first
pnpm run build
# Publish to GitHub Packages
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}