sabisan/.gitea/workflows/publish.yml
V f807cdd075
Some checks failed
Publish / Lint and test (push) Failing after 2s
Publish / Build and push image (push) Has been skipped
Use image-only Gitea workflows
2026-05-16 21:39:08 +01:00

90 lines
2.4 KiB
YAML

name: Publish
on:
push:
branches:
- main
jobs:
lint-test:
name: Lint and test
runs-on: ubuntu-latest
container:
image: golang:1.24-bookworm
steps:
- name: Checkout
env:
TOKEN: ${{ github.token }}
run: |
set -eu
git init .
if [ -n "${TOKEN:-}" ]; then
server="${GITHUB_SERVER_URL#https://}"
server="${server#http://}"
git remote add origin "https://x-access-token:${TOKEN}@${server}/${GITHUB_REPOSITORY}.git"
else
git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
fi
git fetch --depth=1 origin "${GITHUB_SHA}"
git checkout --detach FETCH_HEAD
- name: Check formatting
run: |
files="$(gofmt -l .)"
if [ -n "$files" ]; then
echo "The following files need gofmt:"
echo "$files"
exit 1
fi
- name: Vet
run: go vet ./...
- name: Test
run: go test ./...
build-push:
name: Build and push image
runs-on: ubuntu-latest
needs: lint-test
container:
image: docker:27-git
steps:
- name: Checkout
env:
TOKEN: ${{ github.token }}
run: |
set -eu
git init .
if [ -n "${TOKEN:-}" ]; then
server="${GITHUB_SERVER_URL#https://}"
server="${server#http://}"
git remote add origin "https://x-access-token:${TOKEN}@${server}/${GITHUB_REPOSITORY}.git"
else
git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
fi
git fetch --depth=1 origin "${GITHUB_SHA}"
git checkout --detach FETCH_HEAD
- name: Read version
run: |
version="$(tr -d '[:space:]' < VERSION)"
if [ -z "$version" ]; then
echo "VERSION file is empty"
exit 1
fi
echo "VERSION=$version" >> "$GITHUB_ENV"
echo "IMAGE=k3crpi.jumpingcrab.com:5000/sabisan:$version" >> "$GITHUB_ENV"
- name: Log in to registry
run: |
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login k3crpi.jumpingcrab.com:5000 \
--username "${{ secrets.REGISTRY_USERNAME }}" \
--password-stdin
- name: Build image
run: docker build --pull --tag "$IMAGE" .
- name: Push image
run: docker push "$IMAGE"