Skip to content

Commit

Permalink
Feature: Build binaries and automatically create release on Tag creat…
Browse files Browse the repository at this point in the history
…ion (#47)

* chore: updated linter version

* chore: upgraded deps

* fix: linter issues after upgrading

* feat: build binaries on release, adding tag

* fix: install cross compilation for ARM64

* fix: add new flags for compilation

* fix: turn off arm64 for testing

* fix: trying another version of build configurations

* fix: replaced name, need to test

* chore: minor formatting and spelling fix

* fix: for windows path, suggestion from copilot

* fix: attempt to build with cgo enabled

* fix: adding cache to speed up runs

* fix: removing additional vars

* test: working on linux only release

* fix: for yaml linter

* fix: file extension does not match

* fix: names, tags, deprecated fields

* fix: add changelog and checksums

* feat: added darwin binary

* fix: for removing gcc from darwin

* fix: attempt to fix a perm issue on installing golangci

* fix: add more logging to lint install

* fix: set the gopath env

* fix: attempt to overwrite go if detected

* fix: working on safer brew execution

* fix: only run one install

* chore: cleanup of files

* chore: cleanup old code

* fix: added more timeout to linting

* fix: only install if needed

* fix: improved lint function

* fix: make the ids unique
  • Loading branch information
mrz1836 authored Feb 12, 2024
1 parent e0961c9 commit 2be3e2b
Show file tree
Hide file tree
Showing 14 changed files with 299 additions and 175 deletions.
116 changes: 109 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: release

env:
GO111MODULE: on
GO_VERSION: 1.21

on:
push:
Expand All @@ -13,24 +14,125 @@ permissions:
contents: write

jobs:
goreleaser:
build-linux-binary:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: gcc install
run: sudo apt-get update; sudo apt install gcc-aarch64-linux-gnu
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.21
go-version: ${{ env.GO_VERSION }}
- name: Cache code
uses: actions/cache@v4
with:
path: |
~/go/pkg/mod # Module download cache
~/.cache/go-build # Build cache (Linux)
~/Library/Caches/go-build # Build cache (Mac)
"%LocalAppData%\\go-build" # Build cache (Windows)
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5.0.0
uses: goreleaser/goreleaser-action@v3
with:
distribution: goreleaser
version: latest
args: release --clean --debug
args: release --skip=publish --verbose --config .goreleaser-for-linux.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
#- name: Syndicate to GoDocs
# run: make godocs
- name: Upload
uses: actions/upload-artifact@v4
with:
name: alert_system_linux
path: |
dist/alert_system_*.zip
dist/checksums.txt
dist/CHANGELOG.md
build-darwin-binary:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Cache code
uses: actions/cache@v4
with:
path: |
~/go/pkg/mod # Module download cache
~/.cache/go-build # Build cache (Linux)
~/Library/Caches/go-build # Build cache (Mac)
"%LocalAppData%\\go-build" # Build cache (Windows)
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
version: latest
args: release --skip=publish --verbose --config .goreleaser-for-darwin.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload
uses: actions/upload-artifact@v4
with:
name: alert_system_darwin
path: |
dist/alert_system_*.zip
dist/checksums.txt
dist/CHANGELOG.md
create-release:
needs: [build-linux-binary, build-darwin-binary]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Make directories
run: |
mkdir -p ./dist/linux
mkdir -p ./dist/darwin
mkdir -p ./dist/windows
- name: Download linux binaries
uses: actions/download-artifact@v4
with:
name: alert_system_linux
path: ./tmp-build/linux
- name: Download darwin binaries
uses: actions/download-artifact@v4
with:
name: alert_system_darwin
path: ./tmp-build/darwin
- name: Get tag
uses: little-core-labs/get-git-tag@v3.0.2
id: tag
- name: Prepare ./dist folder
run: |
mkdir -p ./dist
mv ./tmp-build/linux/*.zip ./dist
mv ./tmp-build/darwin/*.zip ./dist
cat ./tmp-build/linux/checksums.txt >> ./dist/checksums.txt
cat ./tmp-build/linux/CHANGELOG.md >> ./dist/CHANGELOG.md
- name: Release
uses: softprops/action-gh-release@v1
with:
body_path: dist/CHANGELOG.md
prerelease: ${{ contains(github.ref, '-rc.') }}
files: |
dist/*.zip
dist/CHANGELOG.md
env:
COMMIT_TAG: ${{steps.tag.outputs.tag}}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
~/go/pkg/mod # Module download cache
~/.cache/go-build # Build cache (Linux)
~/Library/Caches/go-build # Build cache (Mac)
'%LocalAppData%\go-build' # Build cache (Windows)
"%LocalAppData%\\go-build" # Build cache (Windows)
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ run:
concurrency: 4

# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 6m
timeout: 10m

# exit code when at least one issue was found, default is 1
issues-exit-code: 1
Expand Down
56 changes: 56 additions & 0 deletions .goreleaser-for-darwin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Make sure to check the documentation at http://goreleaser.com
# ---------------------------
# General
# ---------------------------
before:
hooks:
- make all
snapshot:
name_template: "{{ .Tag }}"
changelog:
sort: asc
filters:
exclude:
- '^.github:'
- '^.vscode:'
- '^docs:'
- '^test:'

# ---------------------------
# Builder
#
# CGO is enabled and inspiration came from:
# https://github.com/goreleaser/goreleaser-cross-example
# https://github.com/goreleaser/goreleaser-cross-example-sysroot
# https://github.com/DataDog/extendeddaemonset/blob/main/.goreleaser-for-darwin.yaml
# ---------------------------
builds:
- id: darwin-build
main: ./cmd/
binary: alert_system
goos:
- darwin
goarch:
- amd64
- arm64
env:
- CGO_ENABLED=1
mod_timestamp: "{{ .CommitTimestamp }}"
ldflags:
- -s -w -X main.version={{.Version}}

# ---------------------------
# Archives + Checksums
# ---------------------------
archives:
- id: alert_system_darwin
builds:
- darwin-build
name_template: "alert_system_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
wrap_in_directory: false
format: zip
files:
- LICENSE
checksum:
name_template: "checksums.txt"
algorithm: sha256
61 changes: 61 additions & 0 deletions .goreleaser-for-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Make sure to check the documentation at http://goreleaser.com
# ---------------------------
# General
# ---------------------------
before:
hooks:
- make all
snapshot:
name_template: "{{ .Tag }}"
changelog:
sort: asc
filters:
exclude:
- '^.github:'
- '^.vscode:'
- '^docs:'
- '^test:'

# ---------------------------
# Builder
#
# CGO is enabled and inspiration came from:
# https://github.com/goreleaser/goreleaser-cross-example
# https://github.com/goreleaser/goreleaser-cross-example-sysroot
# https://github.com/DataDog/extendeddaemonset/blob/main/.goreleaser-for-linux.yaml
# ---------------------------
builds:
- id: linux-build
main: ./cmd/
binary: alert_system
goos:
- linux
goarch:
- amd64
- arm64
env:
- CGO_ENABLED=1
mod_timestamp: "{{ .CommitTimestamp }}"
ldflags:
- -s -w -X main.version={{.Version}}
overrides:
- goos: linux
goarch: arm64
env:
- CC=aarch64-linux-gnu-gcc

# ---------------------------
# Archives + Checksums
# ---------------------------
archives:
- id: alert_system_linux
builds:
- linux-build
name_template: "alert_system_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
wrap_in_directory: false
format: zip
files:
- LICENSE
checksum:
name_template: "checksums.txt"
algorithm: sha256
103 changes: 0 additions & 103 deletions .goreleaser.yml

This file was deleted.

Loading

0 comments on commit 2be3e2b

Please sign in to comment.