Skip to content

Commit

Permalink
ci(gh-actions): add publish job to build workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
lujoga authored Oct 10, 2023
1 parent 992c9b4 commit 19544e6
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ name: build

on:
push:
branches: [ "main" ]
branches:
- main
tags:
- v*
pull_request:
branches: [ "main" ]
branches:
- main

jobs:
build:
Expand All @@ -25,3 +29,42 @@ jobs:

- name: Test
run: go test -v ./...

publish:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

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

- name: Log in to container registry
if: github.ref_type == 'tag'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Build and push container image
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.ref_type == 'tag' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

0 comments on commit 19544e6

Please sign in to comment.