Skip to content

Merge pull request #39 from homebridge/dependabot/npm_and_yarn/homebr… #12

Merge pull request #39 from homebridge/dependabot/npm_and_yarn/homebr…

Merge pull request #39 from homebridge/dependabot/npm_and_yarn/homebr… #12

name: "Stage 1 - Create a pre-release and build APT package"
on:
workflow_dispatch:
inputs:
increment:
description: 'Release Level'
required: true
default: 'patch'
type: choice
options:
- major
- minor
- patch
push:
branches:
- latest
paths:
- package.json
jobs:
merge_inputs:
# allows for both the workflow_dispatch and push events to trigger this job
runs-on: ubuntu-latest
outputs:
username: ${{ steps.merge_username.outputs.username }}
increment: ${{ steps.merge_increment.outputs.increment }}
steps:
- name: Merge Username
id: merge_username
run: |
if [ "${{ github.event.commits[0].author.username }}" ]; then
USERNAME=${{ github.event.commits[0].author.username }}
else
USERNAME='dependabot[bot]'
fi
echo "Using USERNAME: $USERNAME"
echo "username=$USERNAME" >> "$GITHUB_OUTPUT"
- name: Merge Username
id: merge_increment
run: |
if [ "${{ inputs.increment }}" ]; then
INCREMENT=${{ inputs.increment }}
else
INCREMENT=patch
fi
echo "Using INCREMENT: $INCREMENT"
echo "increment=$INCREMENT" >> "$GITHUB_OUTPUT"
create_draft_prerelease:
# Only run this job if the username is dependabot[bot]
needs: merge_inputs
if: ${{ needs.merge_inputs.outputs.username == 'dependabot[bot]' }}
permissions:
# write permission is required to create a github release
contents: write
# write permission is required for autolabeler
# otherwise, read permission is required at least
pull-requests: write
runs-on: ubuntu-latest
outputs:
version: ${{ steps.release_version.outputs.version }} # Without a V
v-version: ${{ steps.release_version.outputs.v-version }} # With a V
release_type: 'stable'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get next version
uses: reecetech/[email protected]
id: release_version
with:
scheme: semver
increment: ${{ needs.merge_inputs.outputs.increment }}
message_about_not_running:
# Only run this job if the username is dependabot[bot]
needs: merge_inputs
if: ${{ needs.merge_inputs.outputs.username != 'dependabot[bot]' }}
permissions:
# write permission is required to create a github release
contents: write
# write permission is required for autolabeler
# otherwise, read permission is required at least
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Display Message
run: echo "::error::This job is not running automatically because the invoker is not 'dependabot[bot]'." && exit 1
build_package_and_store:
needs: [create_draft_prerelease]
name: Build Packages for (${{ matrix.name }}) v${{ needs.create_draft_prerelease.outputs.version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
name: [
debian-x86_64,
debian-arm32v6,
debian-arm64v8,
]
include:
- name: debian-x86_64
os: ubuntu-latest
BASE_IMAGE: library/debian:bullseye
QEMU_ARCH: x86_64
- name: debian-arm32v6
os: ubuntu-latest
BASE_IMAGE: balenalib/raspberrypi3-debian:bullseye
QEMU_ARCH: arm
- name: debian-arm64v8
os: ubuntu-latest
BASE_IMAGE: arm64v8/debian:bullseye
QEMU_ARCH: aarch64
steps:
- uses: actions/checkout@v4
- name: Linux - Setup Dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get --yes --no-install-recommends install binfmt-support qemu-user-static
docker run --rm --privileged multiarch/qemu-user-static:register --reset
- name: Linux - Build Docker Image
if: runner.os == 'Linux'
run: |
docker build -f build/Dockerfile --build-arg BASE_IMAGE=${{ matrix.BASE_IMAGE }} --build-arg QEMU_ARCH=${{ matrix.QEMU_ARCH }} -t package-build --platform=linux/${{ matrix.QEMU_ARCH }} .
- name: Linux - Build Package
if: runner.os == 'Linux'
run: |
docker run --rm -v $(pwd):/repo -e PKG_RELEASE_TYPE="${{ needs.create_draft_prerelease.outputs.release_type }}" -e PKG_RELEASE_VERSION="${{ needs.create_draft_prerelease.outputs.version }}" package-build
- name: Rename package to include v
run: |
UPDATED=$(ls homebridge*.deb | sed -e 's/homebridge_/homebridge_v/g')
mv homebridge_*.deb ${UPDATED}
- name: Rename manifest to include v
run: |
UPDATED=$(ls homebridge*.manifest | sed -e 's/homebridge_/homebridge_v/g')
mv homebridge_*.manifest ${UPDATED}
- uses: actions/upload-artifact@v4
with:
name: artifacts-${{ matrix.name }}
retention-days: 7
path: |
*.deb
*.manifest
publish_prerelease:
# Publish the pre-release to the GitHub Releases page
needs: [build_package_and_store, create_draft_prerelease]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
pattern: artifacts-*
merge-multiple: true
- name: Display structure of downloaded files
run: ls -R
- name: Get the date
id: date
run: |
echo "builddate=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
- name: Create Release Body
id: release_body
run: |
echo "BODY_FILE=$(ls *.manifest | head -n 1)" >> $GITHUB_OUTPUT
- name: Dump Steps context
env:
STEPS_CONTEXT: ${{ toJson(steps) }}
run: echo "$STEPS_CONTEXT"
- name: Create Pre-Release
uses: docker://ghcr.io/mini-bomba/create-github-release:v1.2.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ needs.create_draft_prerelease.outputs.v-version }}
prerelease: true
draft: false
name: "${{ needs.create_draft_prerelease.outputs.v-version }} - ${{ steps.date.outputs.builddate }}"
files: |
*.deb
*.manifest
body: ${{ steps.release_body.outputs.BODY_FILE }}
clear_attachments: true
fail_on_no_files: true
- name: update release
uses: tubone24/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG_NAME: ${{ needs.create_draft_prerelease.outputs.v-version }}
with:
body_path: ${{ steps.release_body.outputs.BODY_FILE }}
print_context:
runs-on: ubuntu-latest
steps:
- name: Dump Inputs context
env:
INPUTS_CONTEXT: ${{ toJson(inputs) }}
run: echo "$INPUTS_CONTEXT"
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Dump job context
env:
JOB_CONTEXT: ${{ toJson(job) }}
run: echo "$JOB_CONTEXT"
- name: Dump steps context
env:
STEPS_CONTEXT: ${{ toJson(steps) }}
run: echo "$STEPS_CONTEXT"
- name: Dump runner context
env:
RUNNER_CONTEXT: ${{ toJson(runner) }}
run: echo "$RUNNER_CONTEXT"
- name: Dump strategy context
env:
STRATEGY_CONTEXT: ${{ toJson(strategy) }}
run: echo "$STRATEGY_CONTEXT"
- name: Dump matrix context
env:
MATRIX_CONTEXT: ${{ toJson(matrix) }}
run: echo "$MATRIX_CONTEXT"
- name: Show default environment variables
run: |
echo "The job_id is: $GITHUB_JOB" # reference the default environment variables
echo "The id of this action is: $GITHUB_ACTION" # reference the default environment variables
echo "The run id is: $GITHUB_RUN_ID"
echo "The GitHub Actor's username is: $GITHUB_ACTOR"
echo "GitHub SHA: $GITHUB_SHA"