Skip to content

Commit

Permalink
build: package releases for different operating systems (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
zimeg authored Jan 15, 2024
1 parent 6167ebf commit cb59bf9
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 3 deletions.
123 changes: 123 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: Package this version

on:
push:
branches:
- main
tags:
- 'v*'
pull_request:

permissions:
contents: write

jobs:
snapshot:
name: Save a snapshot
if: ${{ ! startsWith(github.ref, 'refs/tags/') }}
runs-on: ubuntu-latest
outputs:
version: ${{ steps.tag.outputs.version }}
steps:
- name: Checkout the repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go environment
uses: actions/setup-go@v5
with:
go-version: '1.21.x'
- name: Create snapshots
uses: goreleaser/goreleaser-action@v5
with:
args: release --clean --snapshot --skip=publish
- name: Collect the current version
id: tag
run: |
echo "version=$(git describe --dirty --always --tags)" >> "$GITHUB_ENV"
echo "version=$(git describe --dirty --always --tags)" >> "$GITHUB_OUTPUT"
- name: Upload the checksums
uses: actions/upload-artifact@v4
with:
name: etime_${{ env.version }}_checksums.txt
path: ./dist/etime_${{ env.version }}_checksums.txt
- name: Cache the moments
uses: actions/cache/save@v3
if: always()
with:
path: ./dist
key: snapshots-${{ github.sha }}

artifacts:
name: Share the artifacts
needs: snapshot
runs-on: ubuntu-latest
env:
version: ${{ needs.snapshot.outputs.version }}
strategy:
matrix:
target:
- darwin_arm64.tar.gz
- darwin_x86_64.tar.gz
- linux_arm64.tar.gz
- linux_i386.tar.gz
- linux_x86_64.tar.gz
- windows_arm64.zip
- windows_i386.zip
- windows_x86_64.zip
steps:
- name: Checkout the repo
uses: actions/checkout@v4
- name: Restore cached snapshots
uses: actions/cache/restore@v3
with:
path: ./dist
key: snapshots-${{ github.sha }}
- name: Upload a snapshot
uses: actions/upload-artifact@v4
with:
name: etime_${{ env.version }}_${{ matrix.target }}
path: ./dist/etime_${{ env.version }}_${{ matrix.target }}

notify:
name: Post a notification
needs: artifacts
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Leave a comment
run: |
PR_COMMENT="Latest builds: https://github.com/$GH_REPO/actions/runs/$GH_RUN_ID"
PR_REF="${{ github.ref_name }}"
if [[ $PR_REF == *"/merge" ]]; then
PR_REF="${PR_REF%%/merge}"
fi
if ! gh pr comment "$PR_REF" --repo "$GH_REPO" --edit-last --body "$PR_COMMENT"; then
gh pr comment "$PR_REF" --repo "$GH_REPO" --body "$PR_COMMENT"
fi
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
GH_RUN_ID: ${{ github.run_id }}

release:
name: Distribute a release
if: ${{ startsWith(github.ref, 'refs/tags/') }}
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go environment
uses: actions/setup-go@v5
with:
go-version: '1.21.x'
- name: Create releases
uses: goreleaser/goreleaser-action@v5
with:
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# binary
# Built binaries
etime
dist/*

# development
# Development leftovers
*.swp
.github/runner
36 changes: 36 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
version: 1

before:
hooks:
- go mod tidy

builds:
- id: etime
binary: etime_{{.Summary}}
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin

archives:
- format: tar.gz
name_template: >-
etime_
{{- .Summary }}_
{{- .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
format_overrides:
- goos: windows
format: zip

changelog:
skip: true

checksum:
name_template: "etime_{{ .Summary }}_checksums.txt"
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Package releases for many different operating systems

### Fixed

- Parse the provided help flag to display a helpful message
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build test
.PHONY: build test release clean

BIN=etime

Expand All @@ -8,6 +8,10 @@ build:
test: build
go test ./...

release: clean
goreleaser build --snapshot

clean:
rm -f $(BIN)
rm -rf ~/.config/etime
rm -rf dist

0 comments on commit cb59bf9

Please sign in to comment.