Skip to content

Commit

Permalink
fix(github-actions): separate build & release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
maxime1907 committed Oct 6, 2023
1 parent 252460f commit 4098ea9
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 107 deletions.
101 changes: 101 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Build

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

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
BINARY_NAME: koherence

jobs:
golang:
name: Golang
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-22.04
include:
- os: ubuntu-22.04
platform: linux
arch: amd64
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.21.2'

- name: Install packages
run: |
sudo apt-get update
sudo apt install -yq --no-install-recommends make
- name: Build
env:
GOOS: ${{ matrix.platform }}
GOARCH: ${{ matrix.arch }}
run: make build

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ env.BINARY_NAME }}-${{ matrix.platform }}-${{ matrix.arch }}
path: ${{ env.BINARY_NAME }}
if-no-files-found: error

container:
name: Containerfile
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-22.04
include:
- os: ubuntu-22.04
platform: linux
arch: amd64
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata
uses: docker/metadata-action@v5
id: metadata
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build image
uses: docker/build-push-action@v5
with:
context: .
file: Containerfile
push: ${{ github.event_name != 'pull_request' }}
platforms: ${{ matrix.platform }}/${{ matrix.arch }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
131 changes: 24 additions & 107 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,120 +1,37 @@
name: Build
name: Release

on:
push:
branches:
- main
workflow_run:
workflows:
- "Build"
types:
- completed
tags:
- 'v*.*.*'
pull_request:
branches:
- main

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
BINARY_NAME: koherence

jobs:
golang:
name: Golang
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-22.04
include:
- os: ubuntu-22.04
platform: linux
arch: amd64
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.21.2'

- name: Install packages
run: |
sudo apt-get update
sudo apt install -yq --no-install-recommends make
- name: Build
env:
GOOS: ${{ matrix.platform }}
GOARCH: ${{ matrix.arch }}
run: make build

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ env.BINARY_NAME }}-${{ matrix.platform }}-${{ matrix.arch }}
path: ${{ env.BINARY_NAME }}
if-no-files-found: error

container:
name: Containerfile
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-22.04
include:
- os: ubuntu-22.04
platform: linux
arch: amd64
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata
uses: docker/metadata-action@v5
id: metadata
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build image
uses: docker/build-push-action@v5
with:
context: .
file: Containerfile
push: ${{ github.event_name != 'pull_request' }}
platforms: ${{ matrix.platform }}/${{ matrix.arch }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}

release:
runs-on: ubuntu-22.04
if: startsWith(github.ref, 'refs/tags/')
needs:
- golang
- container
steps:
- name: Download artifacts
uses: actions/download-artifact@v3

- name: Upload release
env:
TAG_NAME: ${{ github.ref_name }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Package
run: |
sha256sum ${{ env.BINARY_NAME }}-* | sed 's| .*/| |' > sha256sum.txt
gh release create "$TAG_NAME" --draft --title "${{ env.BINARY_NAME }} ${TAG_NAME#jq-}" --generate-notes
gh release upload "$TAG_NAME" --clobber ${{ env.BINARY_NAME }}-* sha256sum.txt
for folder in ./*; do
if [ -d "$folder" ]; then
echo "Processing folder: $folder"
cd $folder
tar -czf ../$folder.tar.gz -T <(\ls -1)
cd ..
sha256sum $folder.tar.gz > $folder.tar.gz.sha256
fi
done
- name: Release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: '*.tar.gz'
tag: ${{ github.ref }}
file_glob: true

0 comments on commit 4098ea9

Please sign in to comment.