Skip to content

Build binaries and container images #181

Build binaries and container images

Build binaries and container images #181

Workflow file for this run

name: Build binaries and container images
on:
push: # temp
workflow_dispatch:
schedule: [ cron: '0 0 * * *' ]
permissions:
packages: write
contents: write
jobs:
build:
runs-on: ubuntu-20.04
outputs:
commit: ${{ steps.meta.outputs.commit }}
version: ${{ steps.meta.outputs.version }}
continue: ${{ steps.meta.outputs.continue }}
strategy:
fail-fast: true
matrix:
arch: [amd64, arm64]
steps:
- uses: actions/checkout@v4
- run: git clone --depth=1 https://codeberg.org/VnPower/PixivFE
- uses: actions/setup-go@v5
with:
go-version-file: PixivFE/go.mod
cache-dependency-path: PixivFE/go.sum
- id: meta
run: |
cd PixivFE
echo "continue=$(diff -u ../.last_commit <(git rev-parse --short HEAD) > /dev/null 2>&1 && echo false || echo true)" >> $GITHUB_OUTPUT
echo "version=$(grep -rPoh "(?<=s.Version = \").*(?=\")")" >> $GITHUB_OUTPUT
echo "commit=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- if: ${{ steps.meta.outputs.continue == 'true' }}
run: |
cd PixivFE
CGO_ENABLED=0 GOOS=linux GOARCH=${{ matrix.arch }} go build -mod=readonly -v -ldflags="-s -w" -o pixivfe
- if: ${{ steps.meta.outputs.continue == 'true' }}
uses: docker/setup-qemu-action@v3
- if: ${{ steps.meta.outputs.continue == 'true' }}
uses: docker/setup-buildx-action@v3
- if: ${{ steps.meta.outputs.continue == 'true' }}
uses: docker/metadata-action@v5
id: image-meta
with:
images: ghcr.io/kankerdev/pixivfe
tags: |
type=raw,value=${{ matrix.arch }}-${{ steps.meta.outputs.version }},enable={{is_default_branch}}
type=raw,value=${{ matrix.arch }}-${{ steps.meta.outputs.commit }},enable={{is_default_branch}}
type=raw,value=${{ matrix.arch }},enable={{is_default_branch}}
- if: ${{ steps.meta.outputs.continue == 'true' }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- if: ${{ steps.meta.outputs.continue == 'true' }}
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') }}
- if: ${{ steps.meta.outputs.continue == 'true' }}
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 }}
- if: ${{ steps.meta.outputs.continue == 'true' }}
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') }}
- if: ${{ steps.meta.outputs.continue == 'true' }}
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.arch }}
path: |
PixivFE/pixivfe
PixivFE/views/
post:
runs-on: ubuntu-latest
needs: [ build ]
if: ${{ needs.build.outputs.continue == 'true' }}
env:
IMAGE: ghcr.io/kankerdev/pixivfe
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 buildx imagetools create \
--tag ${IMAGE}:${COMMIT} ${IMAGE}:a{md,rm}64-${COMMIT}
docker buildx imagetools create \
--tag ${IMAGE}:${VERSION} ${IMAGE}:a{md,rm}64-${VERSION}
docker buildx imagetools create \
--tag ${IMAGE}:latest ${IMAGE}:a{md,rm}64
- run: |
OLD=$(cat .last_commit)
NEW=${COMMIT}
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
echo "${NEW}" > .last_commit
git add .last_commit
git commit -m "Update .last_commit" -m "${OLD} >> ${NEW}"
git status
git push -u origin master