-
-
Notifications
You must be signed in to change notification settings - Fork 153
191 lines (157 loc) · 5.53 KB
/
release.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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
name: Release
on:
push:
tags:
- v*
jobs:
deploy:
name: Deploy server to production
runs-on: ubuntu-latest
environment: esm.sh
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.23.x
- name: Run Deploy Script
run: ./scripts/deploy-ci.sh
env:
GOOS: ${{ secrets.DEPLOY_HOST_OS }}
GOARCH: ${{ secrets.DEPLOY_HOST_ARCH }}
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
DEPLOY_SSH_PORT: ${{ secrets.DEPLOY_SSH_PORT }}
DEPLOY_SSH_USER: ${{ secrets.DEPLOY_SSH_USER }}
DEPLOY_SSH_PRIVATE_KEY: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }}
SERVER_CONFIG: ${{ secrets.SERVER_CONFIG }}
SERVER_VERSION: ${{ github.ref_name }}
push_docker_image:
name: Push docker image to ghcr.io
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ghcr.io/esm-dev/esm.sh:latest,ghcr.io/esm-dev/esm.sh:${{ github.ref_name }}
build-args: SERVER_VERSION=${{ github.ref_name }}
env:
DOCKER_BUILD_RECORD_UPLOAD: false
build_esmsh_cli:
name: Build esm.sh CLI
runs-on: ubuntu-latest
environment: release
strategy:
matrix:
include:
- os: darwin
arch: arm64
ext: ''
- os: darwin
arch: amd64
ext: ''
- os: linux
arch: arm64
ext: ''
- os: linux
arch: amd64
ext: ''
permissions:
contents: read
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.23.x
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
registry-url: 'https://registry.npmjs.org'
- name: Build CLI
run: go build -ldflags="-s -w -X 'github.com/esm-dev/esm.sh/server.VERSION=${{ github.ref_name }}'" -o cli/build/bin/esm.sh-cli-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.ext }} cli/cmd/main.go
env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
CGO_ENABLED: "0"
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: esm.sh-cli-${{ matrix.os }}-${{ matrix.arch }}
path: cli/build/bin/esm.sh-cli-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.ext }}
if-no-files-found: error
- name: Create package.json
run: echo "const[minor,patch='0']='${{ github.ref_name }}'.slice(1).split('_');const p=JSON.parse(require('fs').readFileSync('../npm/package.json','utf8'));console.log(JSON.stringify({...p,name:'@esm.sh/cli-${{ matrix.os }}-${{ matrix.arch }}',version:['0',minor,patch].join('.'),os:['${{ matrix.os }}'],cpu:['${{ matrix.arch }}'.replace('amd','x')],bin:void 0,scripts:void 0,optionalDependencies:void 0}))" | node > package.json
working-directory: cli/build
- name: Publish Package to NPM
run: npm publish --provenance --access public
working-directory: cli/build
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publish_esmsh_to_npm:
name: Publish package "esm.sh" to NPM
runs-on: ubuntu-latest
environment: release
needs: [build_esmsh_cli]
permissions:
contents: read
id-token: write
steps:
- name: Checkout
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 Version
run: echo "const fs=require('fs');const[minor,patch='0']='${{ github.ref_name }}'.slice(1).split('_');fs.writeFileSync('package.json',fs.readFileSync('package.json','utf8').replaceAll('*',['0',minor,patch].join('.')),'utf8')" | node
working-directory: cli/npm
- name: Publish Package
run: npm publish --provenance --access public
working-directory: cli/npm
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
release:
name: Release
runs-on: ubuntu-latest
needs: [deploy, push_docker_image, publish_esmsh_to_npm]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download Artifact
uses: actions/download-artifact@v4
with:
merge-multiple: true
path: .artifact
- name: Gzip Artifact
run: gzip .artifact/*
- name: Extract Release Note
run: echo "console.log(require('fs').readFileSync('CHANGELOG.md','utf8').split('## ')[1].slice('${{ github.ref_name }}'.length).trim())" | node > release-note.txt
- name: Release
uses: softprops/action-gh-release@v2
with:
body_path: release-note.txt
files: .artifact/esm.sh-cli-*.gz