-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (88 loc) · 3.08 KB
/
publish.yml
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
name: Publish to NPM
on:
push:
branches:
- main
- develop
workflow_dispatch:
inputs:
release_type:
description: 'Release type (stable/alpha)'
required: true
default: 'stable'
type: choice
options:
- stable
- alpha
permissions:
contents: write
jobs:
version-and-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org/'
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
- name: Set Release Type
id: release_type
run: |
if [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then
echo "type=alpha" >> $GITHUB_OUTPUT
elif [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "type=stable" >> $GITHUB_OUTPUT
else
echo "type=${{ inputs.release_type }}" >> $GITHUB_OUTPUT
fi
- name: Install Dependencies
run: |
if [[ "${{ steps.release_type.outputs.type }}" == "alpha" ]]; then
pnpm run preinstall:develop && pnpm install
else
pnpm run preinstall:stable && pnpm install
fi
- name: Build
run: |
if [[ "${{ steps.release_type.outputs.type }}" == "alpha" ]]; then
pnpm run build:develop
else
pnpm run build:stable
fi
- name: Get Next Version
id: semantic
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pnpm add -D semantic-release @semantic-release/git @semantic-release/changelog @semantic-release/commit-analyzer @semantic-release/release-notes-generator @semantic-release/npm
OUTPUT=$(unset GITHUB_ACTIONS && npx semantic-release --dry-run --no-ci)
VERSION=$(echo "$OUTPUT" | grep -o "The next release version is [0-9]*\.[0-9]*\.[0-9]*" | awk '{print $6}')
if [[ "${{ steps.release_type.outputs.type }}" == "alpha" ]]; then
VERSION="${VERSION}-alpha.$(date +%s)"
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Update Version
run: |
npm version ${{ steps.semantic.outputs.version }} --no-git-tag-version
- name: Publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
if [[ "${{ steps.release_type.outputs.type }}" == "alpha" ]]; then
pnpm publish --access=public --tag alpha --no-git-checks
else
pnpm publish --access=public --no-git-checks
fi
- name: Create Git Tag
if: success()
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git tag -a "v${{ steps.semantic.outputs.version }}" -m "Release v${{ steps.semantic.outputs.version }}"
git push origin "v${{ steps.semantic.outputs.version }}"