Skip to content

Commit b935c6c

Browse files
committed
Add github workflow
1 parent 7c3c796 commit b935c6c

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Build Go Server
2+
3+
on:
4+
push:
5+
branches:
6+
- main_go
7+
- try/*
8+
pull_request:
9+
branches:
10+
- main_go
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v5
22+
with:
23+
go-version: '1.24.1'
24+
check-latest: true
25+
26+
- name: Set artifact name and development version
27+
id: set-artifact-props
28+
run: |
29+
# Get branch name
30+
if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
31+
BRANCH_NAME="${GITHUB_HEAD_REF}"
32+
else
33+
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
34+
fi
35+
36+
# Clean branch name for artifact naming
37+
CLEAN_NAME="$(echo "$BRANCH_NAME" | sed -E 's/^(b|feat\/|try\/)//g' | sed -e 's/ /_/g' | sed -e 's/\//_/g')"
38+
echo "Clean branch name is: $CLEAN_NAME"
39+
40+
RUN_NUMBER=${{ github.run_number }}
41+
VERSION="${CLEAN_NAME}_${RUN_NUMBER}"
42+
43+
echo "build-name=$VERSION" >> $GITHUB_OUTPUT
44+
echo "version=$VERSION" >> $GITHUB_OUTPUT
45+
46+
echo "Using artifact name: filepi-${VERSION}"
47+
echo "Using version: $VERSION"
48+
49+
- name: Get dependencies
50+
run: go mod download
51+
52+
- name: Build for Linux ARM64 (M1 Mac/RPi 64-bit)
53+
run: |
54+
GOOS=linux GOARCH=arm64 go build -ldflags="-X main.Version=${{ steps.set-artifact-props.outputs.version }}" -o filepi-${{ steps.set-artifact-props.outputs.build-name }}-linux-arm64
55+
tar -czvf filepi-${{ steps.set-artifact-props.outputs.build-name }}-linux-arm64.tar.gz filepi-${{ steps.set-artifact-props.outputs.build-name }}-linux-arm64
56+
57+
- name: Build for Linux x86_64
58+
run: |
59+
GOOS=linux GOARCH=amd64 go build -ldflags="-X main.Version=${{ steps.set-artifact-props.outputs.version }}" -o filepi-${{ steps.set-artifact-props.outputs.build-name }}-linux-amd64
60+
tar -czvf filepi-${{ steps.set-artifact-props.outputs.build-name }}-linux-amd64.tar.gz filepi-${{ steps.set-artifact-props.outputs.build-name }}-linux-amd64
61+
62+
- name: Upload Linux ARM64 build
63+
uses: actions/upload-artifact@v4
64+
with:
65+
name: filepi-${{ steps.set-artifact-props.outputs.build-name }}-linux-arm64
66+
path: filepi-${{ steps.set-artifact-props.outputs.build-name }}-linux-arm64.tar.gz
67+
retention-days: 14
68+
69+
- name: Upload Linux x86_64 build
70+
uses: actions/upload-artifact@v4
71+
with:
72+
name: filepi-${{ steps.set-artifact-props.outputs.build-name }}-linux-amd64
73+
path: filepi-${{ steps.set-artifact-props.outputs.build-name }}-linux-amd64.tar.gz
74+
retention-days: 14
75+
76+
- name: List artifacts
77+
run: |
78+
echo "The following artifacts have been created:"
79+
echo "- filepi-${{ steps.set-artifact-props.outputs.build-name }}-linux-arm64.tar.gz (for Raspberry Pi 64-bit and M1 Mac Linux VMs)"
80+
echo "- filepi-${{ steps.set-artifact-props.outputs.build-name }}-linux-amd64.tar.gz (for x86_64 Linux)"

0 commit comments

Comments
 (0)