mirror of
https://github.com/Luzifer/go-latestver.git
synced 2024-11-09 15:40:04 +00:00
Add Docker publishing
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
cc21eb3297
commit
2c50565137
2 changed files with 75 additions and 10 deletions
45
.github/workflows/test-and-build.yml
vendored
45
.github/workflows/test-and-build.yml
vendored
|
@ -16,7 +16,7 @@ jobs:
|
|||
shell: bash
|
||||
|
||||
container:
|
||||
image: luzifer/archlinux
|
||||
image: luzifer/gh-arch-env
|
||||
env:
|
||||
CGO_ENABLED: 1
|
||||
GOPATH: /go
|
||||
|
@ -24,19 +24,14 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Enable custom AUR package repo
|
||||
run: echo -e "[luzifer]\nSigLevel = Never\nServer = https://archrepo.hub.luzifer.io/\$arch" >>/etc/pacman.conf
|
||||
|
||||
- name: Install required packages
|
||||
run: |
|
||||
pacman -Syy --noconfirm \
|
||||
base-devel \
|
||||
git \
|
||||
go \
|
||||
golangci-lint-bin \
|
||||
sqlite3
|
||||
base-devel
|
||||
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
show-progress: false
|
||||
|
||||
- name: Marking workdir safe
|
||||
run: git config --global --add safe.directory /__w/go-latestver/go-latestver
|
||||
|
@ -45,4 +40,34 @@ jobs:
|
|||
run: |
|
||||
make go_test
|
||||
|
||||
docker-publish:
|
||||
if: ${{ startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/master' }}
|
||||
|
||||
needs:
|
||||
- test-and-build
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
permissions:
|
||||
packages: write
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
show-progress: false
|
||||
|
||||
- name: Log into registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Docker Build & Publish
|
||||
run: bash ci/docker-publish.sh
|
||||
|
||||
...
|
||||
|
|
40
ci/docker-publish.sh
Normal file
40
ci/docker-publish.sh
Normal file
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
function log() {
|
||||
echo "[$(date +%H:%M:%S)] $@" >&2
|
||||
}
|
||||
|
||||
[[ -n $GITHUB_REF_NAME ]] || {
|
||||
log "ERR: This script is intended to run on a Github Action only."
|
||||
exit 1
|
||||
}
|
||||
|
||||
repo="ghcr.io/${GITHUB_REPOSITORY,,}"
|
||||
tags=()
|
||||
|
||||
case "${GITHUB_REF_TYPE}" in
|
||||
branch)
|
||||
# Generic build to develop: Workflow has to limit branches to master
|
||||
tags+=(develop)
|
||||
;;
|
||||
tag)
|
||||
# Build to latest: Older tags are not intended to rebuild
|
||||
tags+=(develop latest ${GITHUB_REF_NAME})
|
||||
;;
|
||||
*)
|
||||
log "ERR: The ref type ${GITHUB_REF_TYPE} is not handled."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
log "Building Docker image..."
|
||||
docker build -t "${repo}:local" .
|
||||
|
||||
for ref in "${tags[@]}"; do
|
||||
log "Pushing Docker image to '${repo}:${ref}'..."
|
||||
docker tag "${repo}:local" "${repo}:${ref}"
|
||||
docker push "${repo}:${ref}"
|
||||
done
|
||||
|
||||
log "Publish finished."
|
Loading…
Reference in a new issue