This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build binaries and container images | |
on: | |
push: # temp | |
workflow_dispatch: | |
schedule: [ cron: '0 4 * * *' ] | |
permissions: | |
packages: write | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-20.04 | |
outputs: | |
commit: ${{ steps.compile-step.outputs.commit }} | |
version: ${{ steps.compile-step.outputs.version }} | |
strategy: | |
fail-fast: true | |
matrix: | |
arch: [amd64, arm64] | |
steps: | |
- uses: actions/checkout@v4 | |
with: { fetch-depth: 0 } | |
- run: git clone https://codeberg.org/VnPower/PixivFE | |
- uses: actions/setup-go@v5 | |
with: | |
check-latest: true | |
go-version-file: PixivFE/go.mod | |
cache-dependency-path: PixivFE/go.sum | |
- id: compile-step | |
run: | | |
cd PixivFE | |
CGO_ENABLED=0 GOOS=linux GOARCH=${{ matrix.arch }} go build -mod=readonly -v -ldflags="-s -w" -o pixivfe | |
echo "version=$(grep -rPoh "(?<=s.Version = \").*(?=\")")" >> $GITHUB_OUTPUT | |
echo "commit=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
- uses: docker/setup-qemu-action@v3 | |
- uses: docker/setup-buildx-action@v3 | |
- uses: docker/metadata-action@v5 | |
id: image-meta | |
with: | |
images: ghcr.io/${{ github.repository }} | |
tags: | | |
type=raw,value=${{ matrix.arch }}-${{ steps.compile-step.outputs.version }},enable={{is_default_branch}} | |
type=raw,value=${{ matrix.arch }}-${{ steps.compile-step.outputs.commit }},enable={{is_default_branch}} | |
type=raw,value=${{ matrix.arch }},enable={{is_default_branch}} | |
- uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- uses: actions/cache/restore@v4 | |
id: docker-cache-restore | |
with: | |
path: .docker_cache | |
key: docker-cache-ubuntu-20.04-matrix-${{ matrix.arch }}-${{ hashFiles('./PixivFE/go.mod', './PixivFE/go.sum', './PixivFE/Dockerfile') }} | |
- uses: docker/build-push-action@v5 | |
with: | |
push: true | |
file: Dockerfile | |
context: ./PixivFE | |
cache-to: type=local,dest=.docker_cache/ | |
cache-from: type=local,src=.docker_cache/ | |
platforms: linux/${{ matrix.arch }} | |
tags: ${{ steps.image-meta.outputs.tags }} | |
labels: ${{ steps.image-meta.outputs.labels }} | |
- uses: actions/cache/save@v4 | |
id: docker-cache-save | |
with: | |
path: .docker_cache | |
key: docker-cache-ubuntu-20.04-matrix-${{ matrix.arch }}-${{ hashFiles('./PixivFE/go.mod', './PixivFE/go.sum', './PixivFE/Dockerfile') }} | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.arch }} | |
path: | | |
PixivFE/pixivfe | |
PixivFE/views/ | |
post: | |
runs-on: ubuntu-latest | |
needs: [ build ] | |
env: | |
IMAGE: ghcr.io/${{ github.repository }} | |
COMMIT: ${{ needs.build.outputs.commit }} | |
VERSION: ${{ needs.build.outputs.version }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: { fetch-depth: 0 } | |
- uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- run: docker version | |
- run: | | |
docker manifest create ${IMAGE}:${COMMIT} \ | |
--amend ${IMAGE}:{amd,arm}64-${COMMIT} | |
docker manifest create ${IMAGE}:${VERSION} \ | |
--amend ${IMAGE}:{amd,arm}64-${VERSION} | |
docker manifest create ${IMAGE}:latest \ | |
--amend ${IMAGE}:{amd,arm}64 | |
docker manifest push ${IMAGE}:${COMMIT} | |
docker manifest push ${IMAGE}:${VERSION} | |
docker manifest push ${IMAGE}:latest |