Split into build and release

This commit is contained in:
Antony Messerli 2022-05-22 10:24:08 -05:00 committed by GitHub
parent cb241d29fa
commit 54968c57b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 139 additions and 13 deletions

View File

@ -1,8 +1,8 @@
name: build
on:
push:
pull_request:
branches:
- 'master'
- master
workflow_dispatch:
jobs:
@ -110,7 +110,7 @@ jobs:
if: steps.version_check.outcome == 'success' && steps.version_check.conclusion == 'success'
uses: docker/build-push-action@v2
with:
push: true
push: false
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
@ -123,13 +123,4 @@ jobs:
ghcr.io/netbootxyz/netbootxyz:${{ github.sha }}
ghcr.io/netbootxyz/netbootxyz:${{ env.VERSION_TAG }}
labels: ${{ steps.meta.outputs.labels }}
- name: Bump version and push tag
if: steps.version_check.outcome == 'success' && steps.version_check.conclusion == 'success'
id: tag_version
uses: anothrNick/github-tag-action@1.39.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CUSTOM_TAG: ${{ env.VERSION_TAG }}
WITH_V: true
RELEASE_BRANCHES: master

135
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,135 @@
name: build
on:
push:
branches:
- 'master'
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: '0'
- name: Set env variables
run: |
echo "GITHUB_DATE=$(date +'%Y-%m-%dT%H:%M:%S')" >> $GITHUB_ENV
echo "GITHUB_SHA=${{ github.sha }}" >> $GITHUB_ENV
- name: Get latest Webapp release version
run: |
WEBAPP_RELEASE=$(curl -sX GET "https://api.github.com/repos/netbootxyz/webapp/releases/latest" | jq -r '. | .tag_name')
echo "WEBAPP_RELEASE=${WEBAPP_RELEASE}" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Login to the GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USER }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Determine version numbers
id: version_check
continue-on-error: true
run: |
tag=latest
IMAGE=netbootxyz/netbootxyz
TOKEN=$(curl -sX GET \
"https://ghcr.io/token?scope=repository%3Anetbootxyz%2Fnetbootxyz%3Apull" \
| jq -r '.token')
MULTIDIGEST=$(curl -s \
--header "Accept: application/vnd.docker.distribution.manifest.v2+json" \
--header "Authorization: Bearer ${TOKEN}" \
"https://ghcr.io/v2/${IMAGE}/manifests/${tag}" \
| jq -r 'first(.manifests[].digest)')
DIGEST=$(curl -s \
--header "Accept: application/vnd.docker.distribution.manifest.v2+json" \
--header "Authorization: Bearer ${TOKEN}" \
"https://ghcr.io/v2/${IMAGE}/manifests/${MULTIDIGEST}" \
| jq -r '.config.digest')
IMAGE_INFO=$(curl -sL \
--header "Authorization: Bearer ${TOKEN}" \
"https://ghcr.io/v2/${IMAGE}/blobs/${DIGEST}" \
| jq -r '.config')
IMAGE_RELEASE=$(echo ${IMAGE_INFO} | jq -r '.Labels.build_version' | awk '{print $3}')
IMAGE_VERSION=$(echo ${IMAGE_RELEASE} | awk -F'-nbxyz' '{print $1}')
NB_RELEASE_NUMBER=$(echo ${IMAGE_RELEASE} | awk -F'-nbxyz' '{print $2}')
TAG_SHA=$(git rev-list -n 1 ${IMAGE_RELEASE})
if [ -z "${MULTIDIGEST}" ] || [ "${MULTIDIGEST}" == "null" ]; then
echo "**** No existing container build found, assuming first build ****"
VERSION_TAG=${WEBAPP_RELEASE}-nbxyz1
echo "VERSION_TAG=${VERSION_TAG}" >> $GITHUB_ENV
elif [ "${WEBAPP_RELEASE}" == "${IMAGE_VERSION}" ]; then
echo "**** Version ${WEBAPP_RELEASE} unchanged, checking if there is anything to build..."
if [ "${TAG_SHA}" == "${GITHUB_SHA}" ]; then
echo "**** Nothing to do, exiting build... **** "
exit 1
else
echo "**** Changes found... incrementing build number version... ****"
NB_RELEASE_NUMBER=$((NB_RELEASE_NUMBER + 1))
VERSION_TAG=${IMAGE_VERSION}-nbxyz${NB_RELEASE_NUMBER}
echo "VERSION_TAG=${VERSION_TAG}" >> $GITHUB_ENV
fi
else
echo "**** New version ${WEBAPP_RELEASE} found; old version was ${IMAGE_VERSION}. Generating new webapp release... ****"
VERSION_TAG=${WEBAPP_RELEASE}-nbxyz1
echo "VERSION_TAG=${VERSION_TAG}" >> $GITHUB_ENV
fi
- name: Docker meta
if: steps.version_check.outcome == 'success' && steps.version_check.conclusion == 'success'
id: meta
uses: docker/metadata-action@v4
with:
images: netbootxyz/netbootxyz
labels: |
maintainer=antonym
org.opencontainers.image.created=${{ env.GITHUB_DATE }}
org.opencontainers.image.authors=netboot.xyz
org.opencontainers.image.url=https://github.com/netbootxyz/docker-netbootxyz/packages
org.opencontainers.image.documentation=https://netboot.xyz
org.opencontainers.image.source=https://github.com/netbootxyz/docker-netbootxyz
org.opencontainers.image.version=${{ env.VERSION_TAG }}
org.opencontainers.image.revision=${{ env.GITHUB_SHA }}
org.opencontainers.image.vendor=netboot.xyz
org.opencontainers.image.licenses=Apache-2.0
org.opencontainers.image.ref.name=${{ env.GITHUB_SHA }}
org.opencontainers.image.title=netbootxyz
org.opencontainers.image.description=netboot.xyz official docker container - Your favorite operating systems in one place. A network-based bootable operating system installer based on iPXE.
- name: Build and push image
if: steps.version_check.outcome == 'success' && steps.version_check.conclusion == 'success'
uses: docker/build-push-action@v2
with:
push: true
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
build-args: |
WEBAPP_VERSION=${{ env.WEBAPP_RELEASE }}
VERSION=${{ env.VERSION_TAG }}
BUILD_DATE=${{ env.GITHUB_DATE }}
tags: |
ghcr.io/netbootxyz/netbootxyz:latest
ghcr.io/netbootxyz/netbootxyz:${{ github.sha }}
ghcr.io/netbootxyz/netbootxyz:${{ env.VERSION_TAG }}
labels: ${{ steps.meta.outputs.labels }}
- name: Bump version and push tag
if: steps.version_check.outcome == 'success' && steps.version_check.conclusion == 'success'
id: tag_version
uses: anothrNick/github-tag-action@1.39.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CUSTOM_TAG: ${{ env.VERSION_TAG }}
WITH_V: true
RELEASE_BRANCHES: master