-
Notifications
You must be signed in to change notification settings - Fork 2
119 lines (117 loc) · 4.87 KB
/
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
name: Build and Release fixctl
on:
push:
tags:
- "*.*.*"
branches:
- main
jobs:
build:
name: Build fixctl on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
go-version: [1.22]
steps:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Check out code
uses: actions/checkout@v4
- name: Set up environment
shell: bash
run: |
OS_NAME=$(echo ${{ matrix.os }} | sed 's/-latest//')
SUFFIX=""
if [ $OS_NAME = "windows" ]; then
SUFFIX=".exe"
fi
if [ $OS_NAME = "ubuntu" ]; then
OS_NAME="linux"
fi
echo "SUFFIX=$SUFFIX" >> $GITHUB_ENV
echo "OS_NAME=$OS_NAME" >> $GITHUB_ENV
- name: Build Binary (amd64)
run: |
GOARCH=amd64 go build -ldflags "-s -w -X github.com/someengineering/fixctl/config.Version=v${{ github.ref_name }}" -o "${{ github.workspace }}/release/fixctl-$OS_NAME-amd64-${{ github.ref_name }}$SUFFIX"
shell: bash
- name: Build Binary (arm64)
run: |
GOARCH=arm64 go build -ldflags "-s -w -X github.com/someengineering/fixctl/config.Version=v${{ github.ref_name }}" -o "${{ github.workspace }}/release/fixctl-$OS_NAME-arm64-${{ github.ref_name }}$SUFFIX"
shell: bash
- name: Generate Universal Binary (macOS)
if: matrix.os == 'macos-latest'
run: |
lipo -create -output "${{ github.workspace }}/release/fixctl-$OS_NAME-universal-${{ github.ref_name }}$SUFFIX" "${{ github.workspace }}/release/fixctl-$OS_NAME-amd64-${{ github.ref_name }}$SUFFIX" "${{ github.workspace }}/release/fixctl-$OS_NAME-arm64-${{ github.ref_name }}$SUFFIX"
rm -f "${{ github.workspace }}/release/fixctl-$OS_NAME-amd64-${{ github.ref_name }}$SUFFIX" "${{ github.workspace }}/release/fixctl-$OS_NAME-arm64-${{ github.ref_name }}$SUFFIX"
strip "${{ github.workspace }}/release/fixctl-$OS_NAME-universal-${{ github.ref_name }}$SUFFIX"
shell: bash
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: fixctl-${{ matrix.os }}-${{ github.ref_name }}
path: ${{ github.workspace }}/release/
create_release:
name: Create Release
needs: build
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Set up environment
shell: bash
run: |
echo "FIXCTL_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ${{ github.workspace }}/release
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
draft: false
prerelease: false
files: |
${{ github.workspace }}/release/*/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update-homebrew-formula:
name: Update Homebrew Formula
needs: create_release
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Check out the homebrew-tap repository
uses: actions/checkout@v4
with:
repository: someengineering/homebrew-tap
token: ${{ secrets.SOME_CI_PAT }}
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ${{ github.workspace }}/release
- name: Update formula for Fixctl
run: |
FIXCTL_VERSION=${{ github.ref_name }}
ARTIFACTS_PATH="${{ github.workspace }}/release"
FIXCTL_MACOS_UNIVERSAL_BINARY_SHA256=$(sha256sum $(find "${ARTIFACTS_PATH}" -name "fixctl-macos-universal-${FIXCTL_VERSION}") | awk '{print $1}')
FIXCTL_LINUX_AMD64_BINARY_SHA256=$(sha256sum $(find "${ARTIFACTS_PATH}" -name "fixctl-linux-amd64-${FIXCTL_VERSION}") | awk '{print $1}')
FIXCTL_LINUX_ARM64_BINARY_SHA256=$(sha256sum $(find "${ARTIFACTS_PATH}" -name "fixctl-linux-arm64-${FIXCTL_VERSION}") | awk '{print $1}')
sed \
-e "s|@FIXCTL_VERSION@|${FIXCTL_VERSION}|g" \
-e "s|@FIXCTL_MACOS_UNIVERSAL_BINARY_SHA256@|${FIXCTL_MACOS_UNIVERSAL_BINARY_SHA256}|g" \
-e "s|@FIXCTL_LINUX_AMD64_BINARY_SHA256@|${FIXCTL_LINUX_AMD64_BINARY_SHA256}|g" \
-e "s|@FIXCTL_LINUX_ARM64_BINARY_SHA256@|${FIXCTL_LINUX_ARM64_BINARY_SHA256}|g" \
fixctl.rb.in > fixctl.rb
- name: Commit and push changes
env:
GITHUB_TOKEN: ${{ secrets.SOME_CI_PAT }}
run: |
git config --global user.email "[email protected]"
git config --global user.name "Some CI"
git commit -am "Update Fixctl formula to version ${{ github.ref_name }}"
git push