-
Notifications
You must be signed in to change notification settings - Fork 0
122 lines (103 loc) · 3.67 KB
/
release.yml
File metadata and controls
122 lines (103 loc) · 3.67 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
name: Release
on:
push:
tags:
- 'v*.*.*'
permissions:
contents: write
packages: write
id-token: write
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for changelog
lfs: true # Fetch LFS files (demo GIFs)
- name: Normalize line endings
run: |
# Ensure line endings are normalized according to .gitattributes
# This prevents "dirty state" errors in GoReleaser
git add --renormalize .
git status
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
cache: true
- name: Install cross-compilation toolchains
run: |
sudo apt-get update
sudo apt-get install -y gcc-mingw-w64-x86-64 gcc-aarch64-linux-gnu
- name: Run tests
run: |
go test -v -coverprofile=coverage.txt ./...
mkdir -p /tmp/coverage
mv coverage.txt /tmp/coverage/ || true
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: '~> v2'
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AUR_SSH_PRIVATE_KEY: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: /tmp/coverage/coverage.txt
publish-npm:
name: Publish to NPM
runs-on: ubuntu-latest
needs: release
permissions:
contents: read
id-token: write # Required for npm OIDC trusted publishing
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
registry-url: 'https://registry.npmjs.org'
- name: Update npm for OIDC trusted publishing
run: npm install -g npm@latest # Requires npm >= 11.5.1 for OIDC
- name: Extract version from tag
id: get_version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
# Detect prerelease (contains -, e.g., beta, alpha, rc)
# NPM requires --tag flag for prerelease versions to prevent overwriting "latest"
if [[ "$VERSION" == *-* ]]; then
# Extract prerelease tag (e.g., "beta" from "1.3.0-beta.2")
TAG=$(echo "$VERSION" | sed -E 's/.*-([a-z]+).*/\1/')
echo "TAG=$TAG" >> $GITHUB_OUTPUT
echo "IS_PRERELEASE=true" >> $GITHUB_OUTPUT
echo "📦 Detected prerelease version: $VERSION (tag: $TAG)"
else
echo "TAG=latest" >> $GITHUB_OUTPUT
echo "IS_PRERELEASE=false" >> $GITHUB_OUTPUT
echo "📦 Detected stable version: $VERSION (tag: latest)"
fi
- name: Update package.json version
run: |
cd npm-package
npm version ${{ steps.get_version.outputs.VERSION }} --no-git-tag-version --allow-same-version
- name: Publish to NPM (Prerelease)
if: steps.get_version.outputs.IS_PRERELEASE == 'true'
run: |
cd npm-package
npm publish --access public --tag ${{ steps.get_version.outputs.TAG }}
echo "✅ Published as prerelease with tag: ${{ steps.get_version.outputs.TAG }}"
- name: Publish to NPM (Stable)
if: steps.get_version.outputs.IS_PRERELEASE == 'false'
run: |
cd npm-package
npm publish --access public
echo "✅ Published as stable release with tag: latest"