-
Notifications
You must be signed in to change notification settings - Fork 0
127 lines (111 loc) · 4.18 KB
/
build-and-release.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
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
name: Build and Release
on:
push:
branches:
- "*"
tags:
- "v*"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Get ref
id: branch
run: echo "ref=$(echo $GITHUB_REF | cut -d'/' -f3)" >> $GITHUB_OUTPUT
shell: bash
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.21.3
- name: Build Binaries
id: build
env:
LINUX_AMD_ARCHIVE: sodium-${{ steps.branch.outputs.ref }}-linux-amd64.tar.gz
LINUX_ARM_ARCHIVE: sodium-${{ steps.branch.outputs.ref }}-linux-arm.tar.gz
WIN_AMD_ARCHIVE: sodium-${{ steps.branch.outputs.ref }}-win-amd64.zip
BIN_VERSION: ${{ steps.branch.outputs.ref }}
run: |
echo "Building Linux amd64 binary"
GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=$BIN_VERSION" -o na
tar -czvf ${LINUX_AMD_ARCHIVE} na
rm -v na
echo "Building Linux ARM binary"
GOOS=linux GOARCH=arm go build -ldflags "-X main.version=$BIN_VERSION" -o na
tar -czvf ${LINUX_ARM_ARCHIVE} na
rm -v na
echo "Building Windows amd64 binary"
GOOS=windows GOARCH=amd64 go build -ldflags "-X main.version=$BIN_VERSION" -o na.exe
zip ${WIN_AMD_ARCHIVE} na.exe
rm -v na.exe
ls -lah
- name: Upload binaries to artifacts
if: contains(github.ref, 'refs/tags/v')
uses: actions/upload-artifact@v2
env:
LINUX_AMD_ARCHIVE: sodium-${{ steps.branch.outputs.ref }}-linux-amd64.tar.gz
LINUX_ARM_ARCHIVE: sodium-${{ steps.branch.outputs.ref }}-linux-arm.tar.gz
WIN_AMD_ARCHIVE: sodium-${{ steps.branch.outputs.ref }}-win-amd64.zip
with:
name: binaries
path: |
${{ env.LINUX_AMD_ARCHIVE }}
${{ env.LINUX_ARM_ARCHIVE }}
${{ env.WIN_AMD_ARCHIVE }}
release:
needs: build
runs-on: ubuntu-latest
if: startsWith(github.event.ref, 'refs/tags/v')
permissions: write-all
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Get ref
id: branch
run: echo "ref=$(echo $GITHUB_REF | cut -d'/' -f3)" >> $GITHUB_OUTPUT
shell: bash
- name: Download binaries from artifacts
uses: actions/download-artifact@v2
with:
name: binaries
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: "${{ steps.branch.outputs.ref }}"
release_name: "Sodium ${{ steps.branch.outputs.ref }}"
draft: false
prerelease: false
- name: Upload Linux amd64 Archive
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LINUX_AMD_ARCHIVE: sodium-${{ steps.branch.outputs.ref }}-linux-amd64.tar.gz
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./${{ env.LINUX_AMD_ARCHIVE }}
asset_name: ${{ env.LINUX_AMD_ARCHIVE }}
asset_content_type: application/octet-stream
- name: Upload Linux ARM Archive
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LINUX_ARM_ARCHIVE: sodium-${{ steps.branch.outputs.ref }}-linux-arm.tar.gz
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./${{ env.LINUX_ARM_ARCHIVE }}
asset_name: ${{ env.LINUX_ARM_ARCHIVE }}
asset_content_type: application/octet-stream
- name: Upload Windows amd64 Archive
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WIN_AMD_ARCHIVE: sodium-${{ steps.branch.outputs.ref }}-win-amd64.zip
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./${{ env.WIN_AMD_ARCHIVE }}
asset_name: ${{ env.WIN_AMD_ARCHIVE }}
asset_content_type: application/octet-stream