Skip to content

gh-action: only test if backend files changed #19

gh-action: only test if backend files changed

gh-action: only test if backend files changed #19

Workflow file for this run

name: release
on:
push:
tags:
- "*.*.*"
workflow_dispatch:
jobs:
check-runner:
runs-on: ubuntu-latest
outputs:
runner-label: ${{ steps.set-runner.outputs.runner-label }}
steps:
- name: Set runner
id: set-runner
run: |
runners=$(curl -s -H "Accept: application/vnd.github+json" -H "Authorization: token ${{ secrets.REPO_ACCESS_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/actions/runners")
available=$(echo "$runners" | jq '.runners[] | select(.status == "online" and .busy == false and .labels[] .name == "self-hosted")')
if [ -n "$available" ]; then
echo "runner-label=self-hosted" >> "$GITHUB_OUTPUT"
else
echo "runner-label=ubuntu-latest" >> "$GITHUB_OUTPUT"
fi
goreleaser:
needs: check-runner
runs-on: ${{ needs.check-runner.outputs.runner-label }}
steps:
# pull code
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
# install latest node
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: latest
# build sveltekit frontend
- name: Build frontend
run: |
npm i -g pnpm
pnpm --prefix=./frontend i
PUBLIC_VERSION=${GITHUB_REF##*/} pnpm --prefix=./frontend run build
cp -r ./frontend/build/* ./backend/pb_public/
# setup go
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ">=1.21.1"
# build
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean
workdir: backend
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
docker:
needs:
- goreleaser
- check-runner
runs-on: ${{ needs.check-runner.outputs.runner-label }}
steps:
# pull code
- name: Check Out Repo
uses: actions/checkout@v4
# image tags
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/seriousm4x/UpSnap
tags: |
type=ref,event=tag
type=semver,pattern={{version}}
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}}
# qemu
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
# docker buildx
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
# ghcr.io login
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# build and push
- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: ${{ steps.meta.outputs.tags }}
build-args: |
VERSION=${{github.ref_name}}