forked from goliac-project/goliac
-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (71 loc) · 3.21 KB
/
main.yaml
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
name: Build Docker Image on Tag
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
permissions:
packages: write
contents: write
jobs:
build-binaries:
runs-on: ubuntu-latest
outputs:
linux-x86_64-binary-path: ${{ steps.upload-artifact-linux-x86_64.outputs.binary-path }}
linux-aarch64-binary-path: ${{ steps.upload-artifact-linux-aarch64.outputs.binary-path }}
darwin-arm64-binary-path: ${{ steps.upload-artifact-Darwin-arm64.outputs.binary-path }}
darwin-x86_64-binary-path: ${{ steps.upload-artifact-Darwin-x86_64.outputs.binary-path }}
windows-x86_64-binary-path: ${{ steps.upload-artifact-windows-x86_64.outputs.binary-path }}
steps:
# Checkout the code
- name: Checkout code
uses: actions/checkout@v4
# Set up Go environment
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
# Build Go binaries for different platforms. Name is goliac-`uname -s`-`uname -m` (at least for linux and mac)
- name: Build binaries
run: |
mkdir -p dist
GOOS=linux GOARCH=amd64 go build -ldflags "-X github.com/goliac-project/goliac/internal/config.GoliacBuildVersion=${{ github.ref_name }}" -o dist/goliac-Linux-x86_64 ./cmd/goliac
GOOS=linux GOARCH=arm64 go build -ldflags "-X github.com/goliac-project/goliac/internal/config.GoliacBuildVersion=${{ github.ref_name }}" -o dist/goliac-Linux-aarch64 ./cmd/goliac
GOOS=darwin GOARCH=arm64 go build -ldflags "-X github.com/goliac-project/goliac/internal/config.GoliacBuildVersion=${{ github.ref_name }}" -o dist/goliac-Darwin-arm64 ./cmd/goliac
GOOS=darwin GOARCH=amd64 go build -ldflags "-X github.com/goliac-project/goliac/internal/config.GoliacBuildVersion=${{ github.ref_name }}" -o dist/goliac-Darwin-x86_64 ./cmd/goliac
GOOS=windows GOARCH=amd64 go build -ldflags "-X github.com/goliac-project/goliac/internal/config.GoliacBuildVersion=${{ github.ref_name }}" -o dist/goliac-win-x86_64 ./cmd/goliac
# Publish binaries as release assets
- name: Upload binaries to GitHub Release
uses: softprops/action-gh-release@v2
with:
files: dist/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build:
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: lower-repo
shell: pwsh
run: |
"::set-output name=repository::$($env:GITHUB_REPOSITORY.ToLowerInvariant())"
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ghcr.io/${{ steps.lower-repo.outputs.repository }}:latest,ghcr.io/${{ steps.lower-repo.outputs.repository }}:${{ github.ref_name }}
build-args: |
GITHUB_REF=${{ github.ref_name }}