Skip to content

Commit

Permalink
Add test support for multiplatform builds
Browse files Browse the repository at this point in the history
  • Loading branch information
spijet committed Aug 5, 2021
1 parent 953bf7f commit 9c31db6
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 45 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux, darwin]
goarch: [amd64, arm64]
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.14
go-version: ^1.16
id: go

- name: Check out code into the Go module directory
Expand All @@ -30,10 +34,8 @@ jobs:
- name: Build
run: |
export CGO_ENABLED=0
export CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }}
go build -ldflags "-s -w" \
-trimpath \
-o ./hashcolor \
-o ./hashcolor-${{ matrix.goos }}-${{ matrix.goarch }} \
./cmd/hashcolor/main.go
101 changes: 61 additions & 40 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,82 +1,103 @@
name: Release
name: Create a draft Release

on:
push:
tags: [ "v*" ]

jobs:
build:
name: Build Release
create:
name: Create Release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
go-version: ^1.14
id: go
tag_name: ${{ github.ref }}
release_name: Hashcolor ${{ github.ref }}
draft: true
prerelease: false

build:
name: Build Release binaries
runs-on: ubuntu-latest
needs: create
strategy:
matrix:
goos: [linux, darwin]
goarch: [amd64, arm64]

steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}

- name: Set up Go 1.x
id: go
uses: actions/setup-go@v2
with:
go-version: ^1.16

- name: Get dependencies
run: |
go get -v -t -d ./...
go mod download
go mod verify
- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}

- name: Build
- name: Build Golang binaries (${{ matrix.goos }}/${{ matrix.goarch }})
id: build_binary
env:
CGO_ENABLED: 0
GOOS: "${{ matrix.goos }}"
GOARCH: "${{ matrix.goarch }}"
run: |
export CGO_ENABLED=0
go build -ldflags "-s -w -X main.Version=${{ steps.get_version.outputs.VERSION }}" \
-trimpath -o ./hashcolor \
./cmd/hashcolor/main.go
- name: Package
- name: Package (${{ matrix.goos }}/${{ matrix.goarch }})
env:
CGO_ENABLED: 0
GOOS: "${{ matrix.goos }}"
GOARCH: "${{ matrix.goarch }}"
VERSION: "${{ steps.get_version.outputs.VERSION }}"
run: |
mkdir -p "./build/hashcolor-${{ steps.get_version.outputs.VERSION }}"
cp -av --target-directory="./build/hashcolor-${{ steps.get_version.outputs.VERSION }}" \
mkdir -p "./build/hashcolor-${VERSION}"
cp -av --target-directory="./build/hashcolor-${VERSION}" \
./examples ./hashcolor ./LICENSE ./README.md
cd "./build/hashcolor-${{ steps.get_version.outputs.VERSION }}"
cd "./build/hashcolor-${VERSION}"
find . -type f -exec sha256sum "{}" + > checksums.lst
cd ..
tar cvzf "./hashcolor-${{ steps.get_version.outputs.VERSION }}-linux-x86_64.tar.gz" \
"./hashcolor-${{ steps.get_version.outputs.VERSION }}"
sha256sum "./hashcolor-${{ steps.get_version.outputs.VERSION }}-linux-x86_64.tar.gz" > \
"./hashcolor-${{ steps.get_version.outputs.VERSION }}-linux-x86_64.tar.gz.sha256"
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Hashcolor ${{ github.ref }}
draft: true
prerelease: false
tar cvzf "./hashcolor-${VERSION}-${GOOS}-${GOARCH}.tar.gz" \
"./hashcolor-${VERSION}"
sha256sum "./hashcolor-${VERSION}-${GOOS}-${GOARCH}.tar.gz" > \
"./hashcolor-${VERSION}-${GOOS}-${GOARCH}.tar.gz.sha256"
- name: Upload Release Tarball
- name: Upload Release Tarball (${{ matrix.goos }}/${{ matrix.goarch }})
id: upload-release-tarball
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./build/hashcolor-${{ steps.get_version.outputs.VERSION }}-linux-x86_64.tar.gz
asset_name: hashcolor-${{ steps.get_version.outputs.VERSION }}-linux-x86_64.tar.gz
upload_url: ${{ needs.create.outputs.upload_url }}
asset_path: ./build/hashcolor-${{ steps.get_version.outputs.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz
asset_name: hashcolor-${{ steps.get_version.outputs.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz
asset_content_type: application/gzip

- name: Upload Release Digest
- name: Upload Release Digest (${{ matrix.goos }}/${{ matrix.goarch }})
id: upload-release-digest
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./build/hashcolor-${{ steps.get_version.outputs.VERSION }}-linux-x86_64.tar.gz.sha256
asset_name: hashcolor-${{ steps.get_version.outputs.VERSION }}-linux-x86_64.tar.gz.sha256
upload_url: ${{ needs.create.outputs.upload_url }}
asset_path: ./build/hashcolor-${{ steps.get_version.outputs.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz.sha256
asset_name: hashcolor-${{ steps.get_version.outputs.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz.sha256
asset_content_type: text/plain

0 comments on commit 9c31db6

Please sign in to comment.