From 5c67a888929e2de4450fee7d2b4a3c205b4488a4 Mon Sep 17 00:00:00 2001 From: Thomas Bouffard <27200110+tbouffard@users.noreply.github.com> Date: Tue, 27 Aug 2024 16:43:05 +0200 Subject: [PATCH] feat: simulate "trigger workflows when new version available on npm" (#373) This simulates what we are achieving in the `bpmn-visualization` repository. Introduce a workflow that sends a repository-dispatch event which triggers the workflow that builds the bpmn-visualization demo for the repository of examples. Additional refactoring - simplify the retrieval of inputs of a workflow_dispatch - bump peter-evans/repository-dispatch from v2 to v3 (mainly to enforce run with Node20) in the shared action --- .../notify-PA-repo-of-new-version/action.yml | 12 +++------- ...-simulate-new-version-available-on-npm.yml | 22 +++++++++++++++++++ ...visualization_version_in_Examples_repo.yml | 8 +++---- ...e_bpmn_visualization_version_in_R_repo.yml | 2 +- ...-trigger-companion-repositories-update.yml | 8 ++++++- .github/workflows/release-R.yml | 2 +- .../workflows/release-bpmn_visualization.yml | 4 ++-- README.md | 6 +++-- 8 files changed, 44 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/post-release-simulate-new-version-available-on-npm.yml diff --git a/.github/actions/notify-PA-repo-of-new-version/action.yml b/.github/actions/notify-PA-repo-of-new-version/action.yml index 11c4309..70fce7c 100644 --- a/.github/actions/notify-PA-repo-of-new-version/action.yml +++ b/.github/actions/notify-PA-repo-of-new-version/action.yml @@ -25,29 +25,23 @@ inputs: runs: using: "composite" steps: - - name: Set VERSION - shell: bash - # in bpmn-visualization-js repo - # run: echo "VERSION=${GITHUB_REF#refs/tags/v*}" >> $GITHUB_ENV - # use the action inputs in the playground - run: echo "VERSION=${{ inputs.VERSION }}" >> $GITHUB_ENV - name: Set CLIENT_PAYLOAD shell: bash run: | if [[ "${{ inputs.BUILD_DEMO_WORKFLOW_ID }}" == '' && "${{ inputs.ARTIFACT_NAME }}" == '' ]]; then echo "CLIENT_PAYLOAD=$( jq -n -c \ - --arg v "${{ env.VERSION }}" \ + --arg v "${{ inputs.VERSION }}" \ '{ version: $v }' )" >> $GITHUB_ENV else echo "CLIENT_PAYLOAD=$( jq -n -c \ - --arg v "${{ env.VERSION }}" \ + --arg v "${{ inputs.VERSION }}" \ --arg dr "${{ github.repository }}" \ --arg dwid "${{ inputs.BUILD_DEMO_WORKFLOW_ID }}" \ --arg an "${{ inputs.ARTIFACT_NAME }}" \ '{ version: $v, build_demo_repo: $dr, build_demo_workflow_id: $dwid, artifact_name: $an }' )" >> $GITHUB_ENV fi - name: Send Repository Dispatch event - uses: peter-evans/repository-dispatch@v2 + uses: peter-evans/repository-dispatch@v3 with: token: ${{ inputs.TOKEN }} repository: process-analytics/${{ inputs.PA_REPOSITORY }} diff --git a/.github/workflows/post-release-simulate-new-version-available-on-npm.yml b/.github/workflows/post-release-simulate-new-version-available-on-npm.yml new file mode 100644 index 0000000..339ea1c --- /dev/null +++ b/.github/workflows/post-release-simulate-new-version-available-on-npm.yml @@ -0,0 +1,22 @@ +# in bpmn-visualization, the repository_dispatch event is sent after the npm publish is done +# here, to ease the testing, this is done in a dedicated workflow triggered manually +name: Simulate the availability of a new version of an npm package +on: + workflow_dispatch: + inputs: + version: + description: 'Version' + required: true + +jobs: + notify: + runs-on: ${{ vars.RUNNER_UBUNTU }} + permissions: + contents: write # to dispatch event + steps: + - name: Send Repository Dispatch event + uses: peter-evans/repository-dispatch@v3 + with: + # use the default GITHUB_TOKEN, this is possible because we are dispatching the same repository + event-type: new_version_available_on_npm + client-payload: "{ version: ${{ inputs.version }} }" diff --git a/.github/workflows/post-release-update_bpmn_visualization_version_in_Examples_repo.yml b/.github/workflows/post-release-update_bpmn_visualization_version_in_Examples_repo.yml index e14a8d3..9df9ec1 100644 --- a/.github/workflows/post-release-update_bpmn_visualization_version_in_Examples_repo.yml +++ b/.github/workflows/post-release-update_bpmn_visualization_version_in_Examples_repo.yml @@ -24,10 +24,10 @@ jobs: updateVersion: runs-on: ${{ vars.RUNNER_UBUNTU }} env: - VERSION: ${{ github.event.client_payload.version || github.event.inputs.version }} - ARTIFACT_NAME: ${{ github.event.client_payload.artifact_name || github.event.inputs.artifact_name }} - BUILD_DEMO_WORKFLOW_ID: ${{ github.event.client_payload.build_demo_workflow_id || github.event.inputs.build_demo_workflow_id }} - BUILD_DEMO_REPO: ${{ github.event.client_payload.build_demo_repo || github.event.inputs.build_demo_repo }} + VERSION: ${{ github.event.client_payload.version || inputs.version }} + ARTIFACT_NAME: ${{ github.event.client_payload.artifact_name || inputs.artifact_name }} + BUILD_DEMO_WORKFLOW_ID: ${{ github.event.client_payload.build_demo_workflow_id || inputs.build_demo_workflow_id }} + BUILD_DEMO_REPO: ${{ github.event.client_payload.build_demo_repo || inputs.build_demo_repo }} steps: - uses: actions/checkout@v4 - name: Update examples diff --git a/.github/workflows/post-release-update_bpmn_visualization_version_in_R_repo.yml b/.github/workflows/post-release-update_bpmn_visualization_version_in_R_repo.yml index 6636e7a..0eb6008 100644 --- a/.github/workflows/post-release-update_bpmn_visualization_version_in_R_repo.yml +++ b/.github/workflows/post-release-update_bpmn_visualization_version_in_R_repo.yml @@ -12,7 +12,7 @@ jobs: updateVersion: runs-on: ${{ vars.RUNNER_UBUNTU }} env: - VERSION: ${{ github.event.client_payload.version || github.event.inputs.version }} + VERSION: ${{ github.event.client_payload.version || inputs.version }} steps: - uses: actions/checkout@v4 - name: Get the old version of bpmn-visualization diff --git a/.github/workflows/post-release-upload-demo-archive-and-trigger-companion-repositories-update.yml b/.github/workflows/post-release-upload-demo-archive-and-trigger-companion-repositories-update.yml index d4f3059..d241782 100644 --- a/.github/workflows/post-release-upload-demo-archive-and-trigger-companion-repositories-update.yml +++ b/.github/workflows/post-release-upload-demo-archive-and-trigger-companion-repositories-update.yml @@ -1,6 +1,8 @@ name: Upload Demo Archive & Trigger Companion Repositories Update on: + repository_dispatch: + types: [ new_version_available_on_npm ] workflow_dispatch: inputs: version: @@ -10,8 +12,12 @@ on: jobs: upload_demo_archive: runs-on: ${{ vars.RUNNER_UBUNTU }} + env: + VERSION: ${{ github.event.client_payload.version || inputs.version }} steps: - uses: actions/checkout@v4 + with: + ref: v${{ env.VERSION }} - name: Setup node run: echo "Done" - name: Install dependencies @@ -32,4 +38,4 @@ jobs: BUILD_DEMO_WORKFLOW_ID: "post-release-upload-demo-archive-and-trigger-companion-repositories-update.yml" ARTIFACT_NAME: '${{ env.ARTIFACT_NAME }}' TOKEN: ${{ secrets.GH_RELEASE_TOKEN }} - VERSION: ${{ inputs.version }} + VERSION: ${{ env.VERSION }} diff --git a/.github/workflows/release-R.yml b/.github/workflows/release-R.yml index a2ac3e8..2fb2339 100644 --- a/.github/workflows/release-R.yml +++ b/.github/workflows/release-R.yml @@ -12,7 +12,7 @@ jobs: runs-on: ${{ vars.RUNNER_UBUNTU }} steps: - run: | - echo "New version type: ${{ github.event.inputs.type }}" + echo "New version type: ${{ inputs.type }}" - name: Setup checkout uses: actions/checkout@v4 diff --git a/.github/workflows/release-bpmn_visualization.yml b/.github/workflows/release-bpmn_visualization.yml index c177f5d..49042cf 100644 --- a/.github/workflows/release-bpmn_visualization.yml +++ b/.github/workflows/release-bpmn_visualization.yml @@ -12,7 +12,7 @@ jobs: runs-on: ${{ vars.RUNNER_UBUNTU }} steps: - run: | - echo "New version type: ${{ github.event.inputs.type }}" + echo "New version type: ${{ inputs.type }}" - name: Setup node uses: actions/setup-node@v4 with: @@ -30,6 +30,6 @@ jobs: run: git checkout master && git pull --tags - name: Bump Version run: | - npm version ${{ github.event.inputs.type }} --message "chore(release): %s" + npm version ${{ inputs.type }} --message "chore(release): %s" - name: Push Version run: git push && git push --tags diff --git a/README.md b/README.md index 6bec342..182684d 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ GitHub pages environment generated by this repository **TODO they are going to move in another repositories as they are not playground workflows.** See [#229](https://github.com/process-analytics/github-actions-playground/issues/229). -- [List installed softwares on GitHub runners](list-installed-packages-and-tools.yml): see [#78](https://github.com/process-analytics/github-actions-playground/pull/78) for rationale +- [List installed software on GitHub runners](.github/workflows/list-installed-packages-and-tools.yml): see [#78](https://github.com/process-analytics/github-actions-playground/pull/78) for rationale ## Release simulation @@ -42,6 +42,8 @@ The [Release of bpmn-visualization](.github/workflows/release-bpmn_visualization Then, you can run a [dedicated workflow](.github/workflows/post-release-upload-demo-archive-and-trigger-companion-repositories-update.yml) builds a fake demo, attaches it as an artifact and sends a `repository_dispatch` event to simulate notification of companion repositories as done in `bpmn-visualization`. +[Another workflow](.github/workflows/post-release-simulate-new-version-available-on-npm.yml) can be triggered manually to simulate the availability of a new version of the npm package. It will send a `repository_dispatch` event that will trigger the workflow mentioned above. + **NOTE**: in the bpmn-visualization repository, this workflow is triggered automatically. The event is received by the repository which triggers workflows (simulate what happen in companion repositories) @@ -52,7 +54,7 @@ The event is received by the repository which triggers workflows (simulate what ### bpmn-visualization-examples When a tag is pushed in this repository, a new GitHub draft release is created as it is done in bpmn-visualization-examples. -See the related [worfklow](.github/workflows/post-release-create-gh-release_Examples_repo.yml). +See the related [workflow](.github/workflows/post-release-create-gh-release_Examples_repo.yml). ### bpmnVisualizationR