forked from microsoft/typescript-go
-
Notifications
You must be signed in to change notification settings - Fork 0
154 lines (128 loc) · 4.4 KB
/
release.yml
File metadata and controls
154 lines (128 loc) · 4.4 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
name: Release
on:
push:
tags:
- 'v*'
permissions:
contents: write
defaults:
run:
shell: bash
jobs:
build:
name: Build ${{ matrix.archive_suffix }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- goos: linux
goarch: amd64
archive_suffix: linux-x64
binary_name: tsgo
- goos: linux
goarch: arm64
archive_suffix: linux-arm64
binary_name: tsgo
- goos: darwin
goarch: amd64
archive_suffix: macos-x64
binary_name: tsgo
- goos: darwin
goarch: arm64
archive_suffix: macos-arm64
binary_name: tsgo
- goos: windows
goarch: amd64
archive_suffix: windows-x64
binary_name: tsgo.exe
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- uses: ./.github/actions/setup-go
- name: Determine version
id: version
run: |
VERSION="${GITHUB_REF_NAME#v}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Build release archive
id: package
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: |
set -euo pipefail
VERSION="${VERSION:?}"
TARGET="typescript-go-${VERSION}-${{ matrix.archive_suffix }}"
OUT_DIR="dist/${TARGET}"
BIN_NAME="${{ matrix.binary_name }}"
mkdir -p "$OUT_DIR"
go build \
-trimpath \
-tags "noembed,release" \
-ldflags "-s -w -X github.com/microsoft/typescript-go/internal/core.version=${VERSION}" \
-o "$OUT_DIR/$BIN_NAME" \
./cmd/tsgo
cp LICENSE "$OUT_DIR/"
cp NOTICE.txt "$OUT_DIR/"
ARCHIVE_NAME="${TARGET}.zip"
mkdir -p artifacts
zip -9 -j "artifacts/${ARCHIVE_NAME}" "$OUT_DIR"/*
echo "archive-path=artifacts/${ARCHIVE_NAME}" >> "$GITHUB_OUTPUT"
- name: Upload release artifact
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: tsgo-${{ matrix.archive_suffix }}-${{ steps.version.outputs.version }}
path: ${{ steps.package.outputs.archive-path }}
publish:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Download build artifacts
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
with:
path: release
merge-multiple: true
- name: Create source archive
run: |
set -euo pipefail
RAW_TAG="${GITHUB_REF_NAME}"
VERSION="${RAW_TAG#v}"
ARCHIVE_FOLDER="typescript-go-${VERSION}"
ARCHIVE_NAME="${ARCHIVE_FOLDER}-source.zip"
TMP_DIR="$(mktemp -d)"
SOURCE_DIR="${TMP_DIR}/${ARCHIVE_FOLDER}"
mkdir -p "${SOURCE_DIR}"
rsync -a \
--exclude='.git/' \
--exclude='release/' \
--exclude='node_modules/' \
--exclude='testdata/' \
./ "${SOURCE_DIR}/"
mkdir -p release
(cd "${TMP_DIR}" && zip -9 -r "${GITHUB_WORKSPACE}/release/${ARCHIVE_NAME}" "${ARCHIVE_FOLDER}")
- name: Create or update GitHub release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
RAW_TAG="${GITHUB_REF_NAME}"
VERSION="${RAW_TAG#v}"
TITLE="TypeScript Go ${VERSION}"
NOTES="Release ${VERSION}"
REPO="${GITHUB_REPOSITORY}"
shopt -s nullglob
ASSETS=(release/*.zip)
if [ ${#ASSETS[@]} -eq 0 ]; then
echo "No release assets found" >&2
exit 1
fi
if gh release view "$RAW_TAG" --repo "$REPO" >/dev/null 2>&1; then
gh release edit "$RAW_TAG" --repo "$REPO" --title "$TITLE" --notes "$NOTES"
gh release upload "$RAW_TAG" "${ASSETS[@]}" --repo "$REPO" --clobber
else
gh release create "$RAW_TAG" "${ASSETS[@]}" --repo "$REPO" --title "$TITLE" --notes "$NOTES" --latest --verify-tag
fi