Merge pull request #11 from someengineering/lloesche/useragent #63
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |