Skip to content

Commit

Permalink
chore(linux): Use workflow_dispatch instead of repository_dispatch
Browse files Browse the repository at this point in the history
This makes it possible to manually trigger workflow runs.

Closes #9548.
  • Loading branch information
ermshiperete committed Oct 26, 2023
1 parent 85c39ad commit 1a2a85a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 31 deletions.
64 changes: 42 additions & 22 deletions .github/workflows/deb-packaging.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
name: "Ubuntu packaging"
run-name: "Ubuntu packaging - ${{ github.event.client_payload.branch }} (branch ${{ github.head_ref }}), by @${{ github.actor }}"
run-name: "Ubuntu packaging - ${{ github.event.inputs.branch }} (branch ${{ github.head_ref }}), by @${{ github.actor }}"
on:
repository_dispatch:
types: ['deb-release-packaging:*', 'deb-pr-packaging:*']
workflow_dispatch:
inputs:
ref:
description: 'For a PR `refs/pull/<PR-NUMBER>/merge`'
required: true
headRef:
description: 'The ref of HEAD. For a PR `refs/pull/<PR-NUMBER>/head`.'
required: true
branch:
description: 'The branch. For a PR `PR-<PR-NUMBER>`.'
required: true
default: 'master'
baseBranch:
description: 'For a PR the base branch, otherwise the same as `branch`.'
required: true
default: 'master'
baseRef:
description: 'The ref of the previous commit. For a PR the same as `baseBranch`.'
required: true
user:
description: 'The user that triggered the build or created the PR'
required: true
isTestBuild:
description: 'True if this is a test build. False if this is a release build.'
required: false
default: 'true'

env:
COLOR_GREEN: "\e[32m"
GH_TOKEN: ${{ github.token }}
Expand All @@ -17,26 +42,21 @@ jobs:
outputs:
VERSION: ${{ steps.version_step.outputs.VERSION }}
PRERELEASE_TAG: ${{ steps.prerelease_tag.outputs.PRERELEASE_TAG }}
GIT_SHA: ${{ steps.set_status.outputs.GIT_SHA }}
GHA_TEST_BUILD: ${{ github.event.client_payload.isTestBuild }}
GHA_BRANCH: ${{ github.event.client_payload.branch }}
steps:
- name: Checkout
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c #v3.3.0
with:
ref: '${{ github.event.client_payload.ref }}'
ref: '${{ github.event.inputs.ref }}'

- name: Set pending status on PR builds
id: set_status
if: github.event.client_payload.isTestBuild == 'true'
if: github.event.inputs.isTestBuild == 'true'
shell: bash
run: |
GIT_SHA="${{ github.event.client_payload.sha }}"
echo "GIT_SHA=$GIT_SHA" >> $GITHUB_OUTPUT
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
/repos/$GITHUB_REPOSITORY/statuses/$GIT_SHA \
/repos/$GITHUB_REPOSITORY/statuses/${{ github.sha }} \
-f state='pending' \
-f target_url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" \
-f description='Debian packaging started' \
Expand Down Expand Up @@ -72,19 +92,19 @@ jobs:
id: prerelease_tag
shell: bash
run: |
if [ "${{ github.event.client_payload.isTestBuild }}" == "true" ]; then
PRERELEASE_TAG="~${{ github.event.client_payload.branch }}-$GITHUB_RUN_NUMBER.$GITHUB_RUN_ATTEMPT"
if [ "${{ github.event.inputs.isTestBuild }}" == "true" ]; then
PRERELEASE_TAG="~${{ github.event.inputs.branch }}-$GITHUB_RUN_NUMBER.$GITHUB_RUN_ATTEMPT"
else
PRERELEASE_TAG=""
fi
echo "PRERELEASE_TAG=$PRERELEASE_TAG" >> $GITHUB_OUTPUT
- name: Output which branch or PR we're building plus name of .dsc file
run: |
if [ "${{ github.event.client_payload.isTestBuild }}" == "true" ]; then
echo ":checkered_flag: **Test build of version ${{ steps.version_step.outputs.VERSION }} for ${{ github.event.client_payload.branch }}**" >> $GITHUB_STEP_SUMMARY
if [ "${{ github.event.inputs.isTestBuild }}" == "true" ]; then
echo ":checkered_flag: **Test build of version ${{ steps.version_step.outputs.VERSION }} for ${{ github.event.inputs.branch }}**" >> $GITHUB_STEP_SUMMARY
else
echo ":ship: **Release build of ${{ github.event.client_payload.branch }} branch (${{ github.event.client_payload.ref}}), version ${{ steps.version_step.outputs.VERSION }}**" >> $GITHUB_STEP_SUMMARY
echo ":ship: **Release build of ${{ github.event.inputs.branch }} branch (${{ github.event.inputs.ref}}), version ${{ steps.version_step.outputs.VERSION }}**" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo ":gift: Generated source package:" >> $GITHUB_STEP_SUMMARY
Expand Down Expand Up @@ -146,7 +166,7 @@ jobs:
needs: [sourcepackage, binary_packages]
runs-on: ubuntu-latest
environment: "deploy (linux)"
if: github.event.client_payload.isTestBuild == 'false'
if: github.event.inputs.isTestBuild == 'false'

steps:
- name: Sign packages
Expand All @@ -165,7 +185,7 @@ jobs:
needs: [sourcepackage, deb_signing]
runs-on: self-hosted
environment: "deploy (linux)"
if: github.event.client_payload.isTestBuild == 'false'
if: github.event.inputs.isTestBuild == 'false'

steps:
- name: Install dput
Expand Down Expand Up @@ -195,7 +215,7 @@ jobs:

- name: Upload
run: |
case ${{ github.event.client_payload.branch }} in
case ${{ github.event.inputs.branch }} in
stable-*) destination='' ;;
beta) destination='-proposed' ;;
*) destination='-experimental' ;;
Expand Down Expand Up @@ -227,7 +247,7 @@ jobs:
- name: Checkout
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c #v3.3.0
with:
ref: '${{ github.event.client_payload.ref }}'
ref: '${{ github.event.inputs.ref }}'

- name: Download Artifacts
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
Expand Down Expand Up @@ -259,7 +279,7 @@ jobs:
name: Set result status on PR builds
needs: [sourcepackage, binary_packages, api_verification]
runs-on: ubuntu-latest
if: ${{ always() && github.event.client_payload.isTestBuild == 'true' }}
if: ${{ always() && github.event.inputs.isTestBuild == 'true' }}
steps:
- name: Set success
if: needs.sourcepackage.result == 'success' && needs.binary_packages.result == 'success' && needs.api_verification.result == 'success'
Expand All @@ -284,7 +304,7 @@ jobs:
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
/repos/$GITHUB_REPOSITORY/statuses/${{ needs.sourcepackage.outputs.GIT_SHA }} \
/repos/$GITHUB_REPOSITORY/statuses/${{ github.sha }} \
-f state="$RESULT" \
-f target_url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" \
-f description="$MSG" \
Expand Down
19 changes: 10 additions & 9 deletions resources/build/trigger-builds.inc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,31 @@ function triggerGitHubActionsBuild() {
local IS_TEST_BUILD="$1"
local GITHUB_ACTION="$2"
local GIT_BRANCH="${3:-master}"
local GIT_REF GIT_SHA
local GIT_REF GIT_HEAD_REF

local GITHUB_SERVER=https://api.github.com/repos/keymanapp/keyman/dispatches
local GITHUB_SERVER=https://api.github.com/repos/keymanapp/keyman

if [ "${action:-""}" == "commit" ]; then
# This will only be true if we created and pushed a tag
GIT_REF="refs/tags/release@$VERSION_WITH_TAG"
GIT_SHA="$(git rev-parse "${GIT_REF}")"
GIT_HEAD_REF="${GIT_REF}"
GIT_EVENT_TYPE="${GITHUB_ACTION}: release@${VERSION_WITH_TAG}"
elif [[ $GIT_BRANCH != stable-* ]] && [[ $GIT_BRANCH =~ [0-9]+ ]]; then
GIT_REF="refs/pull/${GIT_BRANCH}/merge"
GIT_SHA="$(git rev-parse "refs/pull/${GIT_BRANCH}/head")"
GIT_HEAD_REF="refs/pull/${GIT_BRANCH}/head"
GIT_EVENT_TYPE="${GITHUB_ACTION}: PR #${GIT_BRANCH}"
GIT_BRANCH="PR-${GIT_BRANCH}"
else
GIT_REF="refs/heads/${GIT_BRANCH}"
GIT_SHA="$(git rev-parse "${GIT_REF}")"
GIT_HEAD_REF="${GIT_REF}"
GIT_EVENT_TYPE="${GITHUB_ACTION}: ${GIT_BRANCH}"
fi

local DATA="{\"event_type\": \"$GIT_EVENT_TYPE\", \
\"client_payload\": { \
local DATA="{
\"ref\": \"$GIT_REF\", \
\"inputs\": { \
\"ref\": \"$GIT_REF\", \
\"sha\": \"$GIT_SHA\", \
\"headRef\": \"$GIT_HEAD_REF\", \
\"branch\": \"$GIT_BRANCH\", \
\"isTestBuild\": \"$IS_TEST_BUILD\" \
}}"
Expand All @@ -106,5 +107,5 @@ function triggerGitHubActionsBuild() {
--header "Accept: application/vnd.github+json" \
--header "Authorization: token $GITHUB_TOKEN" \
--data "$DATA" \
$GITHUB_SERVER
${GITHUB_SERVER}/actions/workflows/deb-packaging.yml/dispatches
}

0 comments on commit 1a2a85a

Please sign in to comment.