chore(flare): Update to v1.9.0 #509
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 images | |
permissions: | |
packages: write | |
contents: write | |
on: | |
pull_request: | |
branches: | |
- main | |
push: | |
branches: | |
- main | |
paths-ignore: | |
- '.github/**' | |
- 'README.md' | |
jobs: | |
setup: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.matrix.outputs.matrix }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
- name: Get changed files | |
id: changed-files | |
uses: tj-actions/changed-files@v34 | |
- name: find-docker-files.py to generate notification matrix | |
id: matrix | |
run: | | |
.github/bin/find-docker-files.py ${{ steps.changed-files.outputs.all_changed_files }} >/tmp/matrix | |
cat /tmp/matrix | |
echo "matrix=$(cat /tmp/matrix)" >> $GITHUB_OUTPUT | |
build: | |
if: ${{ needs.setup.outputs.matrix != '' }} | |
environment: ${{ github.event_name == 'push' && 'main' || 'dev' }} | |
needs: | |
- setup | |
runs-on: "${{ matrix.runner }}" | |
timeout-minutes: 240 | |
outputs: | |
targettag: ${{ steps.targettag.outputs.value }} | |
refsha: ${{ steps.refsha.outputs.value }} | |
combined_tag: ${{ steps.targettag.outputs.value }}-${{ steps.refsha.outputs.value }} | |
manifest: ${{ steps.manifest_output.outputs.value }} | |
strategy: | |
fail-fast: false | |
max-parallel: 3 | |
matrix: "${{ fromJson(needs.setup.outputs.matrix) }}" | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: docker/setup-qemu-action@v2 | |
- uses: docker/setup-buildx-action@v2 | |
with: | |
driver-opts: network=host | |
- name: Log in to the Container registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set manifest output | |
id: manifest_output | |
run: | | |
echo "value=${{ matrix.manifest }}" >> $GITHUB_OUTPUT | |
- name: Set target tag default | |
id: targettag | |
run: | | |
TARGET_TAG=${{ matrix.target }} | |
if [ -z "$TARGET_TAG" ]; then | |
export TARGET_TAG=target | |
fi | |
echo "value=${TARGET_TAG}" >> $GITHUB_OUTPUT | |
- name: Set reference sha | |
id: refsha | |
run: | | |
export REF_SHA="${{ github.event.pull_request.base.sha }}" | |
if [ -z "$REF_SHA" ]; then | |
export REF_SHA=${{ github.event.before }} | |
if [ -z "$REF_SHA" ]; then | |
export REF_SHA=${{ github.sha }} | |
fi | |
fi | |
echo "REF_SHA=${REF_SHA}" | |
echo "value=${REF_SHA}" >> $GITHUB_OUTPUT | |
- name: mkdir /tmp/.buildx-cache | |
run: | | |
mkdir -p /tmp/.buildx-cache | |
- name: Build and push | |
id: docker_build | |
uses: docker/build-push-action@v3 | |
with: | |
context: "{{defaultContext}}:${{ matrix.base }}" | |
push: false | |
file: "Dockerfile" | |
target: "${{ matrix.target }}" | |
tags: | | |
ghcr.io/${{ github.repository_owner }}/${{ matrix.base }}:latest | |
ghcr.io/${{ github.repository_owner }}/${{ matrix.base }}:${{ steps.targettag.outputs.value }} | |
ghcr.io/${{ github.repository_owner }}/${{ matrix.base }}:${{ steps.refsha.outputs.value }} | |
ghcr.io/${{ github.repository_owner }}/${{ matrix.base }}:${{ matrix.version }} | |
ghcr.io/${{ github.repository_owner }}/${{ matrix.base }}:${{ steps.targettag.outputs.value }}-${{ matrix.version }} | |
build-args: | | |
git_version=${{ matrix.git_version }} | |
cache-from: | | |
${{ secrets.TEST != '' && | |
format('type=registry,ref=ghcr.io/{0}/{1}:buildcache-{2}-{3}', github.repository_owner, matrix.base, steps.targettag.outputs.value, matrix.version) || | |
format('type=local,src=/tmp/.buildx-cache') }} | |
cache-to: | | |
${{ secrets.TEST != '' && | |
format('type=registry,ref=ghcr.io/{0}/{1}:buildcache-{2}-{3}', github.repository_owner, matrix.base, steps.targettag.outputs.value, matrix.version) || | |
format('type=local,dest=/tmp/.buildx-cache,mode=max') }} | |
secrets: | | |
GIT_AUTH_TOKEN=${{ secrets.GITHUB_TOKEN }} | |
outputs: ${{ github.event_name == 'push' && format('{0}={1}', 'type', 'registry') || format('type=docker,dest=/tmp/{0}.tar', matrix.base) }} | |
- name: Upload artifact | |
if: ${{ github.event_name != 'push' }} | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ matrix.base }} | |
path: /tmp/${{ matrix.base }}.tar | |
extract_artifacts: | |
environment: ${{ github.event_name == 'push' && 'main' || 'dev' }} | |
needs: | |
- setup | |
- build | |
runs-on: "${{ matrix.runner }}" | |
timeout-minutes: 240 | |
strategy: | |
fail-fast: false | |
max-parallel: 3 | |
matrix: "${{ fromJson(needs.setup.outputs.matrix) }}" | |
if: ${{ needs.build.outputs.manifest != '' }} | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: docker/setup-qemu-action@v2 | |
- uses: docker/setup-buildx-action@v2 | |
with: | |
driver-opts: network=host | |
- name: Download artifact | |
if: ${{ github.event_name != 'push' }} | |
uses: actions/download-artifact@v3 | |
with: | |
name: ${{ matrix.base }} | |
path: /tmp | |
- name: Load image | |
if: ${{ github.event_name != 'push' }} | |
run: | | |
docker load --input /tmp/${{ matrix.base }}.tar | |
docker image ls -a | |
- name: Extract and push binaries | |
run: | | |
CONTAINER_TAG="${{ format('ghcr.io/{0}/{1}:{2}-{3}', github.repository_owner, matrix.base, needs.build.outputs.targettag, matrix.version) }}" | |
CONTAINER="$(docker create ${CONTAINER_TAG})" | |
BIN_TMP_DIR="/tmp/${{ matrix.base }}" | |
mkdir -p "${BIN_TMP_DIR}" | |
for FILE_NAME in ${{ matrix.manifest }}; do | |
BASE_FILE_NAME="$(basename ${FILE_NAME})" | |
docker cp ${CONTAINER}:${FILE_NAME} ${BIN_TMP_DIR}/${BASE_FILE_NAME} | |
mkdir -p "/tmp/deb/$(dirname ${FILE_NAME})" | |
cp -R ${BIN_TMP_DIR}/${BASE_FILE_NAME} /tmp/deb/${FILE_NAME} | |
done | |
if [ "$(ls -A $BIN_TMP_DIR)" ]; then | |
mkdir -p /tmp/archive | |
tar -czvf /tmp/archive/release.tgz -C ${BIN_TMP_DIR} . | |
fi | |
- name: Build deb | |
id: deb_build | |
run: | | |
if [[ "$(ls -A /tmp/deb)" ]]; then | |
export DEBIAN_FRONTEND="noninteractive" | |
sudo apt update && sudo apt install -y dpkg | |
echo "value=$(dpkg --print-architecture)" >> $GITHUB_OUTPUT | |
source /etc/os-release | |
mkdir -p /tmp/packages | |
docker run -t --volume /tmp/packages:/packages:rw \ | |
--volume $(pwd)/.github/bin:/srv \ | |
--volume /tmp/deb:/mnt:rw \ | |
--env CONTAINER_TAG='${{ matrix.version }}' \ | |
--env PROTOCOL_NAME='${{ matrix.base }}' \ | |
--env BUILD_EXEC="$(echo '${{ matrix.manifest }}' | awk '{print $1}')" \ | |
ghcr.io/mackenzie-remote/base-dpkg:jammy \ | |
/srv/build-deb.sh | |
find /tmp/deb | |
fi | |
- name: Upload deb artifacts | |
uses: actions/upload-artifact@v3 | |
if: success() && steps.deb_build.outputs.value != '' && github.event_name != 'push' | |
with: | |
name: deb-artifacts-${{ matrix.base }}-${{ needs.build.outputs.targettag }} | |
path: /tmp/packages/*.deb | |
- name: Upload packaging failure artifacts | |
uses: actions/upload-artifact@v3 | |
if: failure() | |
with: | |
name: deb-failure-artifacts-${{ matrix.base }}-${{ needs.build.outputs.targettag }} | |
path: /tmp/deb/* | |
- name: Merge artifacts | |
run: | | |
mkdir -p /tmp/artifacts | |
for item in "/tmp/${{ matrix.base }}" /tmp/archive /tmp/packages; do | |
if [ -d "${item}" ]; then | |
cp -R ${item}/* /tmp/artifacts/ | |
fi | |
done | |
- name: Create Release | |
if: ${{ github.event_name == 'push' }} | |
uses: softprops/action-gh-release@v1 | |
with: | |
draft: false | |
prerelease: false | |
fail_on_unmatched_files: false | |
tag_name: ${{ matrix.base }}-${{ matrix.version }} | |
name: ${{ matrix.base }}-${{ matrix.version }} | |
body: | | |
Build release for ${{ matrix.base }} version ${{ matrix.version }}. | |
##### Container released to GHCR | |
* https://github.com/oshied/protocol-forge/pkgs/container/${{ matrix.base }} | |
###### Here are the new container tags | |
* `${{ needs.build.outputs.targettag }}` | |
* `${{ needs.build.outputs.targettag }}-${{ matrix.version }}` | |
* `${{ needs.build.outputs.refsha }}` | |
* `${{ matrix.version }}` | |
#### Within this release you'll also find artifacts which can be used for deployments. | |
files: | | |
/tmp/artifacts/* | |
- name: Cleanup | |
run: | | |
sudo rm -rf "/tmp/${{ matrix.base }}" | |
sudo rm -rf /tmp/archive | |
sudo rm -rf /tmp/artifacts | |
sudo rm -rf /tmp/deb | |
sudo rm -rf /tmp/packages | |
complete: | |
# see https://github.community/t/status-check-for-a-matrix-jobs/127354/7 | |
name: Complete CI | |
needs: [setup, build, extract_artifacts] | |
if: ${{ always() }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check all job status | |
# see https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#needs-context | |
# see https://stackoverflow.com/a/67532120/4907315 | |
if: >- | |
${{ | |
contains(needs.*.result, 'failure') | |
|| contains(needs.*.result, 'cancelled') | |
}} | |
run: exit 1 |