Skip to content

Build on upstream release #311

Build on upstream release

Build on upstream release #311

Workflow file for this run

# CI / CD of pr0ton11 builds
name: 'Build on upstream release'
on:
push:
branches:
- main
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
inputs:
version:
description: "Version to release"
required: true
jobs:
check:
name: "Check for updates in upstream"
runs-on: ubuntu-latest
outputs:
upstream: ${{ steps.upstream.outputs.result }}
package: ${{ steps.package.outputs.result }}
steps:
- name: Get latest upstream release
id: upstream
uses: actions/github-script@v6
env:
OWNER: pocketbase
REPO: pocketbase
EXCLUDES: '["draft", "prerelease"]'
with:
result-encoding: string
script: |
const {OWNER,REPO,EXCLUDES} = process.env;
const {data} = await github.rest.repos.listReleases({
owner: OWNER,
repo: REPO
})
const releases = data.filter(release => JSON.parse(EXCLUDES).every(exclude => !release[exclude]))
const latest = releases[0]
return latest.tag_name.replace('v','')
- name: Get latest built version in this repo
id: package
uses: actions/github-script@v6
env:
PACKAGE_NAME: pocketbase
PACKAGE_TYPE: container
with:
result-encoding: string
script: |
const {PACKAGE_NAME,PACKAGE_TYPE} = process.env;
const {data: packages} = await github.rest.packages.getAllPackageVersionsForPackageOwnedByUser({
package_type: PACKAGE_TYPE,
package_name: PACKAGE_NAME,
username: context.repo.owner
})
const latest = packages.filter((p) => p.metadata.container.tags.includes("latest"))[0];
return latest.metadata.container.tags.find((v) => /^v?\d+\.\d+\.\d+$/.test(v)) || '0.0.0'
build:
name: "Build"
runs-on: ubuntu-latest
needs: check
if: (needs.check.outputs.upstream != needs.check.outputs.package) || github.event_name != 'workflow_dispatch'
steps:
- name: "Build:checkout"
uses: actions/checkout@v3
- name: "Build:dockerlogin"
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: "Build:version"
id: version
run: echo "value=${{ github.event.inputs.version || needs.check.outputs.upstream }}" >> $GITHUB_OUTPUT
- name: "Build:dockerversion"
id: meta
uses: docker/metadata-action@v4
with:
images: |
ghcr.io/pr0ton11/pocketbase
tags: |
type=semver,pattern={{version}},value=${{ steps.version.outputs.value }}
type=semver,pattern={{major}}.{{minor}},value=${{ steps.version.outputs.value }}
type=semver,pattern={{major}},value=${{ steps.version.outputs.value }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: "Build:dockerimage"
uses: docker/build-push-action@v3
with:
context: .
push: true
build-args: VERSION=${{ steps.version.outputs.value }}
platforms: linux/amd64,linux/arm64,linux/arm/v7
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max