-
Notifications
You must be signed in to change notification settings - Fork 2
61 lines (49 loc) · 2.02 KB
/
publish-tag.yml
File metadata and controls
61 lines (49 loc) · 2.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
name: Cut a new tag (also auto updates package.json and package-lock.json)
on:
workflow_dispatch:
inputs:
release_type:
description: 'Version bump type (patch, minor, major)'
required: true
default: 'patch'
jobs:
bump-version:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Get triggering user's email
run: |
user_email=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/users/${{ github.actor }} | jq -r '.email')
if [ -z "$user_email" ] || [ "$user_email" == "null" ]; then
user_email="github-actions@github.com"
fi
echo "user_email=$user_email" >> $GITHUB_ENV
- name: Configure Git with the triggering user's info
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com"
- name: Bump version, update manifest, commit and tag
run: |
set -euo pipefail
npm install
# 1) Bump package.json + package-lock.json but DO NOT commit/tag yet
npm version ${{ github.event.inputs.release_type }} --no-git-tag-version
# 2) Read the new version from package.json
NEW_VERSION=$(node -p "require('./package.json').version")
echo "New version is: $NEW_VERSION"
# 3) Update manifest.json's "version" field to match
jq --arg v "$NEW_VERSION" '.version = $v' manifest.json > manifest.json.tmp
mv manifest.json.tmp manifest.json
# 4) Commit everything and create an annotated tag
git add package.json package-lock.json manifest.json
git commit -m "chore: bump version to $NEW_VERSION"
git tag -a "v$NEW_VERSION" -m "v$NEW_VERSION"
# 5) Push commit and tag
git push --follow-tags
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}