Skip to content

Commit bbf8d2a

Browse files
committed
Merge 'feature/update_cli' into 'master'
ci: simplify npm release versioning See merge request: !75
2 parents ab06086 + 639c89a commit bbf8d2a

58 files changed

Lines changed: 7366 additions & 1770 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/release.yml

Lines changed: 135 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,154 @@
1010
# in `goreleaser` to indicate this is being used in a non-interactive mode.
1111
#
1212
name: release
13+
1314
on:
1415
push:
1516
tags:
1617
- 'v*'
18+
1719
permissions:
1820
contents: write
21+
1922
jobs:
20-
goreleaser:
23+
release:
2124
runs-on: ubuntu-latest
25+
defaults:
26+
run:
27+
shell: bash
28+
2229
steps:
23-
-
24-
name: Checkout
25-
uses: actions/checkout@v3
26-
-
27-
name: Unshallow
28-
run: git fetch --prune --unshallow
29-
-
30-
name: Set up Go
31-
uses: actions/setup-go@v3
30+
- name: Checkout
31+
uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 0
34+
35+
- name: Set up Go
36+
uses: actions/setup-go@v5
3237
with:
3338
go-version: 1.17
34-
-
35-
name: Run GoReleaser
39+
40+
- name: Set up Node.js
41+
uses: actions/setup-node@v4
42+
with:
43+
node-version: 20
44+
registry-url: https://registry.npmjs.org
45+
46+
- name: Extract version
47+
id: version
48+
run: |
49+
tag="${GITHUB_REF_NAME}"
50+
version="${tag#v}"
51+
if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
52+
echo "Invalid release tag: $tag" >&2
53+
exit 1
54+
fi
55+
echo "version=$version" >> "$GITHUB_OUTPUT"
56+
57+
- name: Run GoReleaser
3658
uses: goreleaser/goreleaser-action@v3.0.0
3759
with:
3860
version: v1.26.2
39-
args: release --rm-dist
61+
args: release --clean
4062
env:
41-
# GitHub sets this automatically
4263
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+
65+
- name: Install AWS CLI
66+
run: |
67+
python3 -m pip install --user --upgrade awscli
68+
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
69+
70+
- name: Upload release assets to TOS
71+
env:
72+
AWS_ACCESS_KEY_ID: ${{ secrets.TOS_ACCESS_KEY_ID }}
73+
AWS_SECRET_ACCESS_KEY: ${{ secrets.TOS_SECRET_ACCESS_KEY }}
74+
AWS_MAX_ATTEMPTS: "2"
75+
AWS_CLI_CONNECT_TIMEOUT: "10"
76+
AWS_CLI_READ_TIMEOUT: "60"
77+
TOS_BUCKET: ${{ vars.TOS_BUCKET }}
78+
TOS_PREFIX: ${{ vars.TOS_PREFIX }}
79+
TOS_REGION: ${{ vars.TOS_REGION }}
80+
TOS_S3_ENDPOINT: ${{ vars.TOS_S3_ENDPOINT }}
81+
TOS_UPLOAD_CONCURRENCY: ${{ vars.TOS_UPLOAD_CONCURRENCY }}
82+
VERSION: ${{ steps.version.outputs.version }}
83+
run: |
84+
: "${AWS_ACCESS_KEY_ID:?missing secret TOS_ACCESS_KEY_ID}"
85+
: "${AWS_SECRET_ACCESS_KEY:?missing secret TOS_SECRET_ACCESS_KEY}"
86+
87+
export AWS_DEFAULT_REGION="${TOS_REGION:-cn-beijing}"
88+
bucket="${TOS_BUCKET:-eps-common-public}"
89+
prefix="${TOS_PREFIX:-ve}"
90+
endpoint="${TOS_S3_ENDPOINT:-https://tos-s3-cn-beijing.volces.com}"
91+
concurrency="${TOS_UPLOAD_CONCURRENCY:-20}"
92+
destination="s3://${bucket}/${prefix}/v${VERSION}/"
93+
94+
if ! [[ "$concurrency" =~ ^[1-9][0-9]*$ ]]; then
95+
echo "Invalid TOS_UPLOAD_CONCURRENCY: $concurrency" >&2
96+
exit 1
97+
fi
98+
99+
aws configure set default.s3.addressing_style virtual
100+
find dist -maxdepth 1 -type f \( -name '*.zip' -o -name '*SHA256SUMS' \) -print
101+
aws --endpoint-url "$endpoint" s3 ls "s3://${bucket}/${prefix}/" || true
102+
103+
pids=()
104+
while IFS= read -r file; do
105+
echo "Uploading ${file}"
106+
aws --endpoint-url "$endpoint" s3 cp "$file" "$destination" &
107+
pids+=("$!")
108+
109+
if [ "${#pids[@]}" -ge "$concurrency" ]; then
110+
for pid in "${pids[@]}"; do
111+
wait "$pid"
112+
done
113+
pids=()
114+
fi
115+
done < <(find dist -maxdepth 1 -type f \( -name '*.zip' -o -name '*SHA256SUMS' \) -print | sort)
116+
117+
for pid in "${pids[@]}"; do
118+
wait "$pid"
119+
done
120+
121+
aws --endpoint-url "$endpoint" s3 ls "$destination" --recursive
122+
123+
- name: Configure npm package for TOS
124+
env:
125+
TOS_PREFIX: ${{ vars.TOS_PREFIX }}
126+
TOS_PUBLIC_BASE_URL: ${{ vars.TOS_PUBLIC_BASE_URL }}
127+
VERSION: ${{ steps.version.outputs.version }}
128+
run: |
129+
prefix="${TOS_PREFIX:-ve}"
130+
public_base="${TOS_PUBLIC_BASE_URL:-https://cloudcache.volccdn.com}"
131+
download_base="${public_base%/}/${prefix}"
132+
node scripts/configure_npm_release.js "$VERSION" "$download_base"
133+
134+
- name: Verify public TOS download
135+
env:
136+
TOS_PREFIX: ${{ vars.TOS_PREFIX }}
137+
TOS_PUBLIC_BASE_URL: ${{ vars.TOS_PUBLIC_BASE_URL }}
138+
VERSION: ${{ steps.version.outputs.version }}
139+
run: |
140+
prefix="${TOS_PREFIX:-ve}"
141+
public_base="${TOS_PUBLIC_BASE_URL:-https://cloudcache.volccdn.com}"
142+
download_base="${public_base%/}/${prefix}"
143+
archive="volcengine-cli_${VERSION}_linux_amd64.zip"
144+
curl --fail --location --head "${download_base}/v${VERSION}/${archive}"
145+
146+
- name: Test npm package
147+
working-directory: npm
148+
run: |
149+
npm test
150+
npm pack --dry-run
151+
152+
- name: Publish npm package
153+
working-directory: npm
154+
env:
155+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
156+
VERSION: ${{ steps.version.outputs.version }}
157+
run: |
158+
: "${NODE_AUTH_TOKEN:?missing secret NPM_TOKEN}"
159+
npm_tag="latest"
160+
if [[ "$VERSION" == *-* ]]; then
161+
npm_tag="next"
162+
fi
163+
npm publish --access public --tag "$npm_tag"

.gitignore

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,75 @@
44
doc
55
.idea
66
volcengine-cli
7-
ve
7+
/ve
8+
/ve.exe
9+
/bin/ve
10+
/bin/ve.exe
11+
/npm/checksum
12+
/node_modules
13+
14+
# OS
15+
.DS_Store
16+
Thumbs.db
17+
18+
# IDE
19+
.vscode/
20+
.project
21+
.classpath
22+
.sts4-cache/
23+
.history/
24+
.settings
25+
26+
# Temporary files & Caches
27+
.tmp/
28+
.cache/
29+
*.cache
30+
.php_cs.cache
31+
.swp
32+
33+
# Local environment variables
34+
.env
35+
.env.*
36+
!.env.example
37+
!.env.template
38+
39+
# Log files
40+
*.log
41+
logs/
42+
nohup.out
43+
npm-debug.log*
44+
yarn-debug.log*
45+
pytestdebug.log
46+
47+
# Package Files
48+
*.jar
49+
*.war
50+
*.zip
51+
*.tar.gz
52+
*.rar
53+
*.tar
54+
*.gz
55+
*.bz2
56+
*.xz
57+
*.tgz
58+
59+
# Unit test / coverage reports
60+
htmlcov/
61+
.tox/
62+
.coverage
63+
.coverage.*
64+
nosetests.xml
65+
coverage.xml
66+
*.cover
67+
.hypothesis/
68+
.python-version
69+
70+
# Go
71+
*.o
72+
*.a
73+
*.so
74+
*.exe
75+
*.exe~
76+
77+
## Profiling data
78+
*.prof

.goreleaser.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Visit https://goreleaser.com for documentation on how to customize this
22
# behavior.
3+
project_name: volcengine-cli
34
before:
45
hooks:
56
# this is just an example and not a requirement for provider building/publishing
@@ -14,7 +15,7 @@ builds:
1415
flags:
1516
- -trimpath
1617
ldflags:
17-
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'
18+
- '-s -w -X github.com/volcengine/volcengine-cli/cmd.clientVersion={{.Version}}'
1819
goos:
1920
- freebsd
2021
- windows
@@ -28,9 +29,17 @@ builds:
2829
ignore:
2930
- goos: darwin
3031
goarch: '386'
32+
- goos: darwin
33+
goarch: arm
34+
- goos: windows
35+
goarch: arm
3136
binary: ve
3237
archives:
33-
- format: zip
38+
- id: zip
39+
format: zip
40+
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
41+
- id: targz
42+
format: tar.gz
3443
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
3544
checksum:
3645
name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS'

0 commit comments

Comments
 (0)