-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (80 loc) · 2.41 KB
/
nextwp-cli-ci.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
name: "CI/CD: @nextwp/cli"
on:
push:
branches:
- main
tags:
- "nextwp-cli-*"
paths:
- "packages/cli/**"
pull_request:
branches:
- main
jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: "^1.21.4"
- name: Test
run: |
cd packages/cli
go test ./...
build-and-release:
needs: test
name: Build and Upload Artifacts
runs-on: ubuntu-latest
strategy:
matrix:
os: [linux, darwin, windows]
arch: [amd64, arm64]
include:
- os: linux
goos: linux
extension: ""
- os: darwin
goos: darwin
extension: ""
- os: windows
goos: windows
extension: ".exe"
steps:
- uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: "18.19.0"
- name: Install pnpm
run: npm install -g pnpm
- name: Install dependencies
run: pnpm install --prefix packages/cli
- name: Bundle code with esbuild
run: npx esbuild --bundle --minify --sourcemap --platform=node --target=es2015 --format=esm --outdir=package/js packages/cli/js/format.js
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: "^1.21.4"
- name: Build CLI and Package with Dependencies
run: |
VERSION=$(git describe --tags --match "nextwp-cli-*" --always)
echo "Building version $VERSION"
BINARY_NAME="nextwp-cli${{ matrix.extension }}"
ARCHIVE_NAME="nextwp-cli-${{ matrix.goos }}-${{ matrix.arch }}-${VERSION}.zip"
# Build binary
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.arch }} go build -ldflags "-X main.version=$VERSION" -o $BINARY_NAME ./packages/cli/cmd/app
# Copy binary to the package directory
mkdir -p package
cp $BINARY_NAME package/
# Package into a zip file
zip -r $ARCHIVE_NAME package/*
# Move the archive to a distinct directory for uploading
mkdir -p dist
mv $ARCHIVE_NAME dist/
- uses: actions/upload-artifact@v2
with:
name: nextwp-cli-${{ matrix.os }}-${{ matrix.arch }}
path: dist/*