From 107fe141450946014e1efac82161889a1711582b Mon Sep 17 00:00:00 2001 From: Jacob Bandes-Storch Date: Fri, 23 Aug 2024 15:33:59 -0700 Subject: [PATCH] Trigger ide.kaitai.io/devel rebuild after NPM publish (#1124) * Trigger ide.kaitai.io/devel rebuild after NPM publish * updates from review * update workflow * cleanup * GH Actions: fix mismatched environment variable name * trigger-kaitai_struct_webide: also send KSC version Required by https://github.com/kaitai-io/kaitai_struct_webide/commit/f968ac3b23b685b10637f2382bd6f3fef9cf5ea3 --------- Co-authored-by: Petr Pucil --- .github/workflows/main.yml | 6 ++++++ trigger-kaitai_struct_webide | 40 ++++++++++++++++++------------------ 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4172b92c5..c3ad9bd99 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -44,6 +44,12 @@ jobs: env: NPM_API_KEY: ${{ secrets.NPM_TOKEN }} + - name: trigger rebuild of ide.kaitai.io/devel + run: | + ./trigger-kaitai_struct_webide "$(jq -r .version compiler/js/npm/package.json)" + env: + KAITAI_STRUCT_WEBIDE_GITHUB_TOKEN: ${{ secrets.KAITAI_STRUCT_WEBIDE_GITHUB_TOKEN }} + - name: publish ksc to artifacts uses: actions/upload-artifact@v4 with: diff --git a/trigger-kaitai_struct_webide b/trigger-kaitai_struct_webide index 1ae4362ae..737c0142a 100755 --- a/trigger-kaitai_struct_webide +++ b/trigger-kaitai_struct_webide @@ -1,31 +1,31 @@ #!/bin/sh -ef -# https://travis-ci.com/kaitai-io/kaitai_struct_webide needs to be -# rebuilt after we publish newest JS build of ksc to npm. +# ide.kaitai.io/devel needs to be rebuilt after we publish the latest JS build of KSC to npm. + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +ksc_version=$1 PROJECT='kaitai-io/kaitai_struct_webide' -SLUG=$(echo "$PROJECT" | sed 's,/,%2F,g') echo "Triggering build for $PROJECT project..." -if [ -n "$KAITAI_STRUCT_WEBIDE_TOKEN" ]; then - body=' - { - "request": { - "message": "Build with kaitai-struct-compiler v'"$KAITAI_STRUCT_VERSION"'", - "branch": "master" - } - } - ' +if [ -n "$KAITAI_STRUCT_WEBIDE_GITHUB_TOKEN" ]; then + # `event_type` must match the name whitelisted in the CI workflow config in + # https://github.com/kaitai-io/kaitai_struct_webide + body=$(jq -n -c --arg ksc_version "$ksc_version" '{event_type: "rebuild", client_payload: {ksc_version: $ksc_version}}') - echo "$body" + printf '%s\n' "$body" - curl -v -fsSL \ - -H "Content-Type: application/json" \ - -H "Accept: application/json" \ - -H "Travis-API-Version: 3" \ - -H "Authorization: token $KAITAI_STRUCT_WEBIDE_TOKEN" \ + curl -fsSL \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer $KAITAI_STRUCT_WEBIDE_GITHUB_TOKEN" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ -d "$body" \ - "https://api.travis-ci.com/repo/$SLUG/requests" + "https://api.github.com/repos/$PROJECT/dispatches" else - echo "No KAITAI_STRUCT_WEBIDE_TOKEN found!" + echo "No KAITAI_STRUCT_WEBIDE_GITHUB_TOKEN found!" + exit 1 fi