-
Notifications
You must be signed in to change notification settings - Fork 1
90 lines (77 loc) · 3.11 KB
/
go-build.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
name: Go Build
on:
push:
branches:
- main
tags:
- 'v*.*.*'
env:
ARTIFACT_NAME: inventory-app # Define the artifact name here
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
os: [linux, darwin, windows]
arch: [amd64, arm64]
steps:
# Step 1: Check out the repository
- name: Checkout repository
uses: actions/checkout@v3
# Step 2: Set up Go environment
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23'
# Step 3: Install dependencies
- name: Install dependencies
working-directory: ./backend
run: go mod tidy
# Step 4: Build the Go project for each OS/Arch combination
- name: Build
working-directory: ./backend
run: |
# Build binary for the OS/Arch combination, use the ARTIFACT_NAME variable
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -o ${{ env.ARTIFACT_NAME }}-${{ matrix.os }}-${{ matrix.arch }} main.go
# Step 5: Upload the binaries as artifacts
- name: Upload release binary
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}-${{ matrix.os }}-${{ matrix.arch }}
path: ./backend/${{ env.ARTIFACT_NAME }}-${{ matrix.os }}-${{ matrix.arch }}
release:
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
if: startsWith(github.ref, 'refs/tags/')
steps:
# Step 1: Check out the repository
- name: Checkout repository
uses: actions/checkout@v3
# Step 2: Download all artifacts
- name: Download all artifacts
uses: actions/download-artifact@v3
# Step 3: Rename Windows binaries to add .exe extension
- name: Rename Windows Binaries
run: |
mv ${{ env.ARTIFACT_NAME }}-windows-amd64/${{ env.ARTIFACT_NAME }}-windows-amd64 ${{ env.ARTIFACT_NAME }}-windows-amd64/${{ env.ARTIFACT_NAME }}-windows-amd64.exe
mv ${{ env.ARTIFACT_NAME }}-windows-arm64/${{ env.ARTIFACT_NAME }}-windows-arm64 ${{ env.ARTIFACT_NAME }}-windows-arm64/${{ env.ARTIFACT_NAME }}-windows-arm64.exe
# Step 4: Upload the binaries to the release (use variable for artifact name)
- name: Create Release
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: |
${{ env.ARTIFACT_NAME }}-linux-amd64/${{ env.ARTIFACT_NAME }}-linux-amd64
${{ env.ARTIFACT_NAME }}-linux-arm64/${{ env.ARTIFACT_NAME }}-linux-arm64
${{ env.ARTIFACT_NAME }}-darwin-amd64/${{ env.ARTIFACT_NAME }}-darwin-amd64
${{ env.ARTIFACT_NAME }}-darwin-arm64/${{ env.ARTIFACT_NAME }}-darwin-arm64
${{ env.ARTIFACT_NAME }}-windows-amd64/${{ env.ARTIFACT_NAME }}-windows-amd64.exe
${{ env.ARTIFACT_NAME }}-windows-arm64/${{ env.ARTIFACT_NAME }}-windows-arm64.exe
tag: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
body: |
Cross-compiled binaries for multiple platforms.
draft: false
prerelease: false