Skip to content

Commit 4201de8

Browse files
committed
release workflow
1 parent 452ce2e commit 4201de8

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed

.github/workflows/release.yml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: write
10+
11+
defaults:
12+
run:
13+
shell: bash
14+
15+
jobs:
16+
build:
17+
name: Build ${{ matrix.archive_suffix }}
18+
runs-on: ubuntu-latest
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
include:
23+
- goos: linux
24+
goarch: amd64
25+
archive_suffix: linux-x64
26+
binary_name: tsgo
27+
- goos: linux
28+
goarch: arm64
29+
archive_suffix: linux-arm64
30+
binary_name: tsgo
31+
- goos: darwin
32+
goarch: amd64
33+
archive_suffix: macos-x64
34+
binary_name: tsgo
35+
- goos: darwin
36+
goarch: arm64
37+
archive_suffix: macos-arm64
38+
binary_name: tsgo
39+
- goos: windows
40+
goarch: amd64
41+
archive_suffix: windows-x64
42+
binary_name: tsgo.exe
43+
44+
steps:
45+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
46+
47+
- uses: ./.github/actions/setup-go
48+
49+
- name: Determine version
50+
id: version
51+
run: |
52+
VERSION="${GITHUB_REF_NAME#v}"
53+
echo "version=$VERSION" >> $GITHUB_OUTPUT
54+
echo "VERSION=$VERSION" >> $GITHUB_ENV
55+
56+
- name: Build release archive
57+
id: package
58+
env:
59+
GOOS: ${{ matrix.goos }}
60+
GOARCH: ${{ matrix.goarch }}
61+
CGO_ENABLED: 0
62+
run: |
63+
set -euo pipefail
64+
65+
VERSION="${VERSION:?}"
66+
TARGET="typescript-go-${VERSION}-${{ matrix.archive_suffix }}"
67+
OUT_DIR="dist/${TARGET}"
68+
BIN_NAME="${{ matrix.binary_name }}"
69+
70+
mkdir -p "$OUT_DIR"
71+
72+
go build \
73+
-trimpath \
74+
-tags "noembed,release" \
75+
-ldflags "-s -w -X github.com/microsoft/typescript-go/internal/core.version=${VERSION}" \
76+
-o "$OUT_DIR/$BIN_NAME" \
77+
./cmd/tsgo
78+
79+
cp internal/bundled/libs/* "$OUT_DIR/"
80+
cp LICENSE "$OUT_DIR/"
81+
cp NOTICE.txt "$OUT_DIR/"
82+
83+
ARCHIVE_NAME="${TARGET}.zip"
84+
mkdir -p artifacts
85+
(cd dist && zip -9 -r "../artifacts/${ARCHIVE_NAME}" "${TARGET}")
86+
87+
echo "archive-path=artifacts/${ARCHIVE_NAME}" >> "$GITHUB_OUTPUT"
88+
89+
- name: Upload release artifact
90+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
91+
with:
92+
name: tsgo-${{ matrix.archive_suffix }}-${{ steps.version.outputs.version }}
93+
path: ${{ steps.package.outputs.archive-path }}
94+
95+
publish:
96+
needs: build
97+
runs-on: ubuntu-latest
98+
steps:
99+
- name: Download build artifacts
100+
uses: actions/download-artifact@5ada21cd7d6b9e753874d339dbf9b6d3f3c8ba4f # v4.1.8
101+
with:
102+
path: release
103+
merge-multiple: true
104+
105+
- name: Create or update GitHub release
106+
env:
107+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
108+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
109+
run: |
110+
set -euo pipefail
111+
112+
RAW_TAG="${GITHUB_REF_NAME}"
113+
VERSION="${RAW_TAG#v}"
114+
TITLE="TypeScript Go ${VERSION}"
115+
NOTES="Release ${VERSION}"
116+
117+
shopt -s nullglob
118+
ASSETS=(release/*.zip)
119+
if [ ${#ASSETS[@]} -eq 0 ]; then
120+
echo "No release assets found" >&2
121+
exit 1
122+
fi
123+
124+
if gh release view "$RAW_TAG" >/dev/null 2>&1; then
125+
gh release edit "$RAW_TAG" --title "$TITLE" --notes "$NOTES"
126+
gh release upload "$RAW_TAG" "${ASSETS[@]}" --clobber
127+
else
128+
gh release create "$RAW_TAG" "${ASSETS[@]}" --title "$TITLE" --notes "$NOTES" --latest --verify-tag
129+
fi

0 commit comments

Comments
 (0)