Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ci): upload built binaries to GitHub Releases on tag creation #810

Merged
merged 3 commits into from
Aug 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ name: Go Build and Release

on:
push:
branches: [ "main" ]
branches: ["main"]
tags:
- "v*"
pull_request:
branches: [ "main" ]
branches: ["main"]

jobs:
build:
name: Build binaries for Windows, macOS, and Linux
runs-on: ${{ matrix.os }}
permissions:
contents: write
Comment on lines +15 to +16
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should provide the workflow with permissions to upload assets to GitHub releases.

strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
Expand All @@ -20,32 +24,36 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a new Checkout action


- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22.1'
go-version-file: ./go.mod
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stop maintaining the Go version in two places.


- name: Build binary on Linux and macOS
if: matrix.os != 'windows-latest'
env:
OS: ${{ matrix.os == 'ubuntu-latest' && 'linux' || 'darwin' }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebrand the ubuntu-latest binary to linux, and the macos-latest binary to darwin.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strongly suggest removing the "put inside dmg" step on macos/darwin while you're at it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I'm not on the project, or involved in any way, I don't want to remove any functionality in this PR. That's a decision for the maintainers.

I have, however, updated the pipeline to keep the MacOS binary around as well as the dmg in 3b35d88.

GOOS: ${{ matrix.os == 'ubuntu-latest' && 'linux' || 'darwin' }}
GOARCH: ${{ matrix.arch }}
run: |
GOOS=${{ matrix.os == 'ubuntu-latest' && 'linux' || 'darwin' }} \
GOARCH=${{ matrix.arch }} \
go build -o fabric-${{ matrix.os }}-${{ matrix.arch }}-${{ github.ref_name }} .
go build -o fabric-${OS}-${{ matrix.arch }}-${{ github.ref_name }} .

- name: Build binary on Windows
if: matrix.os == 'windows-latest'
env:
OS: windows
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebrand the windows-latest binary to windows

GOOS: windows
GOARCH: ${{ matrix.arch }}
run: |
$env:GOOS = 'windows'
$env:GOARCH = '${{ matrix.arch }}'
go build -o fabric-${{ matrix.os }}-${{ matrix.arch }}-${{ github.ref_name }} .
go build -o fabric-${OS}-${{ matrix.arch }}-${{ github.ref_name }} .

- name: Create DMG for macOS
if: matrix.os == 'macos-latest'
run: |
mkdir dist
mv fabric-macos-latest-${{ matrix.arch }}-${{ github.ref_name }} dist/fabric
cp fabric-macos-latest-${{ matrix.arch }}-${{ github.ref_name }} dist/fabric
hdiutil create dist/fabric-${{ matrix.arch }}.dmg -volname "fabric" -srcfolder dist/fabric
mv dist/fabric-${{ matrix.arch }}.dmg fabric-macos-${{ matrix.arch }}-${{ github.ref_name }}.dmg

Expand All @@ -56,3 +64,8 @@ jobs:
path: |
fabric-${{ matrix.os }}-${{ matrix.arch }}-${{ github.ref_name }}
fabric-macos-${{ matrix.arch }}-${{ github.ref_name }}.dmg

- name: Upload release artifact
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
run: |
gh release upload ${{ github.ref_name }} fabric-*-${{ matrix.arch }}-${{ github.ref_name }}*
Comment on lines +68 to +71
Copy link
Contributor Author

@p5 p5 Aug 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upload the built files to GitHub Releases when invoked from a tag push.
Not entirely sure if this will work, but it will at least attempt to upload the artifacts.