Skip to content

Commit

Permalink
Refactor GitHub Actions workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesLaverack committed Feb 6, 2022
1 parent 1b8e54b commit 67f0bb5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,44 +1,26 @@
name: Create and publish a Docker image
name: Build & Push Container Image

on:
push:
branches: ['main']
workflow_run:
workflows: [Test & Lint]
types: [completed]
branches: [main]
release:
types: [published]
types: [ published ]

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

jobs:
build-and-push-image:
build-and-push:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
permissions:
contents: read
packages: write

steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17.x

- name: Checkout repository
uses: actions/checkout@v2

- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Formatting
run: make fmt vet && git diff-index --quiet HEAD --

- name: Test
run: make test

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
Expand All @@ -51,6 +33,8 @@ jobs:
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/test-and-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Test & Lint

on:
push

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

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17.x

- name: Checkout repository
uses: actions/checkout@v2

- name: Format & Vet
run: make fmt vet && git diff-index --quiet HEAD --

lint:
runs-on: ubuntu-latest

steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17.x

- name: Checkout repository
uses: actions/checkout@v2

- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Test
run: make test

0 comments on commit 67f0bb5

Please sign in to comment.