parent-change #251
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
# This is a basic workflow to help you get started with Actions | |
name: CI | |
# Controls when the workflow will run | |
on: | |
# Triggers the workflow on push or pull request events but only for the main branch | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
# Trigger for parent image update | |
repository_dispatch: | |
types: [parent-change] | |
jobs: | |
build: | |
# The type of runner that the job will run on | |
runs-on: ubuntu-latest | |
permissions: | |
packages: write | |
contents: write | |
env: | |
MAIN_PACKAGE_NAME: platformio | |
ACTIONS_BOT_NAME: github-actions[bot] | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v2 | |
- name: Get current date | |
id: date | |
run: echo "TODAY_IS=$(date +'%Y%m%d')" >> $GITHUB_ENV | |
- name: Get Actions Bot ID | |
id: gbid | |
if: github.event_name != 'pull_request' | |
run: | | |
curl --silent \ | |
--url https://api.github.com/users/$(printf %s "${ACTIONS_BOT_NAME}"|jq -sRr @uri) \ | |
--output bot_info.json | |
echo "::set-output name=bot-id::$(cat bot_info.json | jq --raw-output '.id')" | |
- name: Generate version string | |
id: versionstring | |
run: echo "THIS_VERSTRING=${{ env.TODAY_IS }}.0.${{ github.run_number }}" >> $GITHUB_ENV | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v1 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login to GitHub Container Registry | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Get version from AUR | |
id: getvver | |
run: | | |
curl --silent \ | |
--get \ | |
--data v=5 \ | |
--data type=info \ | |
--data arg=${{ env.MAIN_PACKAGE_NAME }} \ | |
--url https://aur.archlinux.org/rpc \ | |
--output pkg_info.json | |
echo "::set-output name=remote_ver::$(cat pkg_info.json | jq --raw-output '.results[0].Version')" | |
- name: Bump VERSION | |
if: github.event_name != 'pull_request' | |
run: | | |
echo "${{ env.THIS_VERSTRING }} ${{ env.MAIN_PACKAGE_NAME }} ${{ steps.getvver.outputs.remote_ver }}" > VERSION | |
git config --global user.name "${ACTIONS_BOT_NAME%[*}" | |
git config --global user.email "${{ steps.gbid.outputs.bot-id }}+${ACTIONS_BOT_NAME}@users.noreply.github.com" | |
git add VERSION | |
git commit -m "${{ env.THIS_VERSTRING }} version update" | |
- name: Build and export packages | |
uses: docker/build-push-action@v2 | |
with: | |
tags: export | |
target: pkg-export-stage | |
outputs: type=local,dest=out | |
- name: Make image | |
uses: docker/build-push-action@v2 | |
with: | |
load: true | |
tags: testing | |
target: mkimg-stage | |
- name: Test image | |
id: test | |
run: | | |
set -eo pipefail | |
docker run --rm testing bash -c "set -eo pipefail; pacman -Q ${{ env.MAIN_PACKAGE_NAME }} | cut -d ' ' -f2" | tee ver | |
echo "::set-output name=PKG_VER::$(cat ver)" | |
- name: Tag & Push | |
if: github.event_name != 'pull_request' | |
run: | | |
git tag -a "v${{ env.THIS_VERSTRING }}" -m "Has ${{ env.MAIN_PACKAGE_NAME }} ${{ steps.test.outputs.PKG_VER }}" | |
git push -u origin $(git rev-parse --abbrev-ref HEAD) --tags | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v3 | |
with: | |
tags: | | |
type=raw,value=${{ env.THIS_VERSTRING }} | |
type=raw,value=${{ steps.test.outputs.PKG_VER }} | |
flavor: | | |
latest=true | |
images: ghcr.io/${{ github.repository_owner }}/${{ env.MAIN_PACKAGE_NAME }} | |
- name: Docker meta for fw builder | |
id: fw-meta | |
uses: docker/metadata-action@v3 | |
with: | |
tags: | | |
type=raw,value=${{ env.THIS_VERSTRING }} | |
type=raw,value=${{ steps.test.outputs.PKG_VER }} | |
flavor: | | |
latest=true | |
images: ghcr.io/${{ github.repository_owner }}/firmware-builder | |
# Push Docker image with Buildx (don't push on PR) | |
# https://github.com/docker/build-push-action | |
- name: Push to GitHub package registry | |
uses: docker/build-push-action@v2 | |
with: | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
target: mkimg-stage | |
# Push Docker image with Buildx (don't push on PR) | |
# https://github.com/docker/build-push-action | |
- name: Make firmware-builder image and push to GitHub package registry | |
uses: docker/build-push-action@v2 | |
with: | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.fw-meta.outputs.tags }} | |
labels: ${{ steps.fw-meta.outputs.labels }} | |
target: mkfwb-stage | |
# https://docs.github.com/en/rest/reference/releases#create-a-release | |
- name: Make release and upload assets | |
if: github.event_name != 'pull_request' | |
run: | | |
curl --silent \ | |
--url https://api.github.com/repos/${{ github.repository }}/releases \ | |
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ | |
--header "Accept: application/vnd.github.v3+json" \ | |
--data '{"draft":false,"tag_name":"v${{ env.THIS_VERSTRING }}","name":"${{ env.MAIN_PACKAGE_NAME }} ${{ steps.test.outputs.PKG_VER }} via ${{ env.THIS_VERSTRING }}"}' \ | |
--output rel_resp.json | |
echo "Release Done." | |
ASSET_UL_URL=$(cat rel_resp.json | jq --raw-output '.upload_url' | sed "s|{?.*||g") | |
ASSET_UL_URL="${ASSET_UL_URL}?name=asset" | |
for ASSET_FILE in out/* | |
do | |
# upload asset | |
echo "Uploading asset..." | |
# https://docs.github.com/en/rest/reference/releases#upload-a-release-asset | |
curl --silent \ | |
--url "${ASSET_UL_URL}" \ | |
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ | |
--header "Accept: application/vnd.github.v3+json" \ | |
--header "Content-Type: $(file --brief --mime-type ${ASSET_FILE})" \ | |
--data-binary @${ASSET_FILE} \ | |
--output asset_resp.json | |
ASSET_URL=$(cat asset_resp.json | jq --raw-output '.url') | |
echo "Asset upload done." | |
# update asset | |
ASSET_NAME="$(basename ${ASSET_FILE})" | |
echo "Updating asset..." | |
jq -n --arg arg_name "${ASSET_NAME}" '{"name":$arg_name}' | curl --silent \ | |
--request PATCH \ | |
--url "${ASSET_URL}" \ | |
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ | |
--header "Accept: application/vnd.github.v3+json" \ | |
--data @- \ | |
--output asset_update.json | |
echo "Asset update done." | |
if test "$(cat asset_update.json | jq --raw-output '.name')"x != "${ASSET_NAME}"x | |
then | |
echo "Could not verify asset update" | |
exit -1 | |
fi | |
done |