-
Notifications
You must be signed in to change notification settings - Fork 2
136 lines (124 loc) · 3.83 KB
/
_build-base.yml
File metadata and controls
136 lines (124 loc) · 3.83 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
name: Reusable Go Build
on:
workflow_call:
inputs:
goos:
required: true
type: string
description: "Target OS (linux, windows, darwin, etc.)"
goarch:
required: true
type: string
description: "Target architecture (amd64, arm64, arm, etc.)"
goarm:
required: false
type: string
default: ""
description: "ARM version (5, 6, 7)"
gomips:
required: false
type: string
default: ""
description: "MIPS variant (softfloat, hardfloat)"
build_tags:
required: false
type: string
default: ""
description: "Go build tags (e.g., 'ua,sm')"
cgo_enabled:
required: false
type: string
default: "0"
description: "Enable CGO (0 or 1)"
artifact_name:
required: true
type: string
description: "Name for the artifact"
version:
required: true
type: string
description: "Version string (e.g., v1.0.0-build.42)"
runner:
required: false
type: string
default: "ubuntu-latest"
description: "GitHub runner to use"
binary_name:
required: false
type: string
default: "https-vpn"
description: "Output binary name"
outputs:
artifact_path:
description: "Path to built artifact"
value: ${{ jobs.build.outputs.artifact_path }}
build_success:
description: "Whether build succeeded"
value: ${{ jobs.build.outputs.build_success }}
jobs:
build:
runs-on: ${{ inputs.runner }}
outputs:
artifact_path: ${{ steps.build.outputs.artifact_path }}
build_success: ${{ steps.build.outputs.build_success }}
env:
GOOS: ${{ inputs.goos }}
GOARCH: ${{ inputs.goarch }}
GOARM: ${{ inputs.goarm }}
GOMIPS: ${{ inputs.gomips }}
CGO_ENABLED: ${{ inputs.cgo_enabled }}
steps:
- name: Checkout codebase
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true
- name: Get project dependencies
run: go mod download
- name: Build binary
id: build
run: |
mkdir -p build_assets
# Determine binary extension
BINARY_NAME="${{ inputs.binary_name }}"
if [[ "${{ inputs.goos }}" == "windows" ]]; then
BINARY_NAME="${BINARY_NAME}.exe"
fi
# Build tags
BUILD_TAGS=""
if [[ -n "${{ inputs.build_tags }}" ]]; then
BUILD_TAGS="-tags ${{ inputs.build_tags }}"
fi
# Build
echo "Building ${BINARY_NAME} for ${{ inputs.goos }}/${{ inputs.goarch }}..."
go build -o "build_assets/${BINARY_NAME}" \
-trimpath \
-buildvcs=false \
-ldflags="-X main.Version=${{ inputs.version }} -s -w -buildid=" \
${BUILD_TAGS} \
-v ./cmd/https-vpn
# Output
echo "artifact_path=build_assets/${BINARY_NAME}" >> $GITHUB_OUTPUT
echo "build_success=true" >> $GITHUB_OUTPUT
- name: Copy LICENSE and README
run: |
cp LICENSE build_assets/ || true
cp README.md build_assets/ || true
- name: Create archive
run: |
cd build_assets
if [[ "${{ inputs.goos }}" == "windows" ]]; then
zip -9r "../${{ inputs.artifact_name }}.zip" .
else
tar -czvf "../${{ inputs.artifact_name }}.tar.gz" .
fi
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.artifact_name }}
path: |
${{ inputs.artifact_name }}.zip
${{ inputs.artifact_name }}.tar.gz
if-no-files-found: error