Skip to content

Commit

Permalink
chore: Use composite actions for workflows (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
onedr0p authored Jun 10, 2023
1 parent 90c16be commit d618f70
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 124 deletions.
62 changes: 0 additions & 62 deletions .github/actions/docker-image.yaml

This file was deleted.

55 changes: 55 additions & 0 deletions .github/actions/docker-image/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
name: Docker image
description: Creates a Docker image

inputs:
token:
description: Github token
required: true

runs:
using: composite
steps:
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}
flavor: |
latest=true
prefix=v
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

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

- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ inputs.token }}

- name: Build and Push
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ steps.meta.outputs.version }}
BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
26 changes: 0 additions & 26 deletions .github/actions/go-release.yaml

This file was deleted.

24 changes: 24 additions & 0 deletions .github/actions/go-release/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: Binaries
description: Runs Go Releaser

inputs:
token:
description: Github token
required: true

runs:
using: composite
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ">=1.19"

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ inputs.token }}
25 changes: 0 additions & 25 deletions .github/actions/tests.yaml

This file was deleted.

23 changes: 23 additions & 0 deletions .github/actions/tests/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
name: Tests
description: Runs Go tests

runs:
using: composite
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ">=1.19"

- name: Tidy
shell: bash
run: |
go version
go mod tidy
- name: Run Unit tests
shell: bash
run: |
go version
go test -v -race -covermode atomic -coverprofile=covprofile ./...
17 changes: 12 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ on:
- reopened

jobs:
go-tests:
uses: ./.github/actions/tests.yaml
main:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

build:
needs: go-tests
uses: ./.github/actions/docker-image.yaml
- name: Tests
uses: ./.github/actions/tests

- name: Build
uses: ./.github/actions/docker-image
with:
token: "${{ secrets.GITHUB_TOKEN }}"
22 changes: 16 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@ on:
- v*

jobs:
go-tests:
uses: ./.github/actions/tests.yaml
main:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

container-release:
uses: ./.github/actions/docker-image.yaml
- name: Tests
uses: ./.github/actions/tests

go-release:
uses: ./.github/actions/go-release.yaml
- name: Build
uses: ./.github/actions/docker-image
with:
token: "${{ secrets.GITHUB_TOKEN }}"

- name: Release
uses: ./.github/actions/go-release
with:
token: "${{ secrets.GITHUB_TOKEN }}"

0 comments on commit d618f70

Please sign in to comment.