From f4bb80e1976714a97c7cf5165d0aef5595ef9b1b Mon Sep 17 00:00:00 2001 From: Gavin Didrichsen Date: Tue, 23 Apr 2024 12:05:12 +0100 Subject: [PATCH] Use `curl` instead of ruby `octokit` Why? Because the octokit client requires this gem in its environment and I don't want to make any changes to the PDK's Gemfile. An added benefit here with `curl` is that it is alot quicker because there's no need to do a bundle install. Signed-off-by: Gavin Didrichsen --- .../workflow-restarter-proxy/action.yml | 39 ++++++------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/.github/actions/workflow-restarter-proxy/action.yml b/.github/actions/workflow-restarter-proxy/action.yml index e79182455..8b9fe31ce 100644 --- a/.github/actions/workflow-restarter-proxy/action.yml +++ b/.github/actions/workflow-restarter-proxy/action.yml @@ -5,7 +5,7 @@ description: | NOTE: This action cannot itself do the re-start because in effect it's composite steps get folded into the source workflow, the one that "uses" this custom action. Since github does not allow a workflow to retrigger itself, then the source workflow must be triggered not by this but by another workflow. - Therefore, this custom action triggers that other workflow. + Therefore, this custom action triggers that other workflow via the API. inputs: repository: description: 'Should be set to github.repository via the calling workflow' @@ -24,32 +24,17 @@ runs: echo "ERROR: \$SOURCE_GITHUB_TOKEN must be set by the calling workflow" 1>&2 && exit 1 fi - # checkout the repository because I want bundler to have access to my Gemfile - - name: Checkout repository - uses: actions/checkout@v2 - - # setup ruby including a bundle install of my Gemfile - - name: Set up Ruby and install Octokit - uses: ruby/setup-ruby@v1 - with: - ruby-version: '3' - bundler-cache: true # 'bundle install' will be run and gems cached for faster workflow runs - - # Trigger the reusable workflow - - name: Trigger reusable workflow + - name: Trigger reusable workflow via API shell: bash run: | - bundle exec ruby -e " - require 'octokit' - client = Octokit::Client.new(:access_token => '${{ env.SOURCE_GITHUB_TOKEN }}') - client.post( - '/repos/${{ inputs.repository }}/actions/workflows/workflow-restarter.yml/dispatches', - { - ref: 'main', - inputs: { - repo: '${{ inputs.repository }}', - run_id: '${{ inputs.run_id }}' - } + curl -X POST \ + -H "Authorization: token ${{ env.SOURCE_GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/${{ inputs.repository }}/actions/workflows/workflow-restarter.yml/dispatches \ + -d '{ + "ref": "main", + "inputs": { + "repo": "${{ inputs.repository }}", + "run_id": "${{ inputs.run_id }}" } - ) - " + }'