Skip to content

Merge pull request #48 from JenswBE/dependabot/go_modules/github.com/… #55

Merge pull request #48 from JenswBE/dependabot/go_modules/github.com/…

Merge pull request #48 from JenswBE/dependabot/go_modules/github.com/… #55

name: Test, build and publish Golang services
on:
push:
branches: [main]
tags:
- "v*.*.*"
env:
DOCKER_HUB_REPO: jenswbe/github-backup
DOCKER_HUB_USER: jenswbebot
PLATFORMS: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
jobs:
build-services:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Derive docker_tag
id: vars
shell: python
run: |
import os, re, sys
tag = os.environ['GITHUB_REF'].split('/').pop()
print(f"Tag: {tag}")
tags = []
semverRegex = r"^v\d+\.\d+\.\d+$"
if tag == 'main':
tags = ['latest']
elif re.match(semverRegex, tag):
tag_parts = tag.split(".")
tags = ['stable', tag, tag_parts[0], f"{tag_parts[0]}.{tag_parts[1]}"]
else:
sys.exit(f"Invalid tag {tag}. Must be main or a semver tag")
images = []
image_base = os.environ['DOCKER_HUB_REPO']
images = [f"{image_base}:{t}" for t in tags]
images_list = ",".join(images)
print(f"Images: {images_list}")
with open(os.environ['GITHUB_OUTPUT'], 'a') as output:
output.write(f"images={images_list}{os.linesep}")
- uses: actions/setup-go@v5
with:
go-version: "1.22"
check-latest: true
- name: Pull common linter configs
run: wget -O .golangci.yml https://raw.githubusercontent.com/JenswBE/setup/main/programming_configs/golang/.golangci.yml
- name: Lint service
uses: golangci/golangci-lint-action@v6
with:
version: latest
args: >-
--timeout=5m
--disable goerr113
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v6
with:
file: build/package/Dockerfile
platforms: ${{ env.PLATFORMS }}
push: true
tags: ${{ steps.vars.outputs.images }}
- name: Update repo description
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ env.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
repository: ${{ env.DOCKER_HUB_REPO }}