From cc503bfa6280e4aacbee9fb203e472ba858f7a60 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Sat, 27 Jan 2024 15:24:28 +0700 Subject: [PATCH] Refactoring action to use two steps --- action.yml | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/action.yml b/action.yml index 3060b1d..c741dbf 100644 --- a/action.yml +++ b/action.yml @@ -1,31 +1,29 @@ name: "Doc Previewer" description: "Publish a preview of the documentation in a GitHub repository artifact" inputs: - server: + previewer-server: description: "URL of the server where the preview will be published" required: true - job: + artifact-job: description: "Name of the GitHub actions job where the artifact will be uploaded" required: true - token: + github-token: description: "GitHub token available as the `secrets.GITHUB_TOKEN` variable" required: true runs: using: "composite" steps: - name: "Call Doc Previewer Webhook" + id: call-previewer + shell: bash + env: + PREVIEWER_URL: "${{ inputs.previewer-server }}/preview/${{ github.repository }}/${{ github.event.issue.number }}" + ARTIFACT_JOB: "${{ inputs.artifact-job }}" + run: echo "previewer-response=$(curl -X POST -f --data-urlencode \"job=${JOB}\" ${PREVIEWER_URL})" >> "$GITHUB_OUTPUT" + - name: "Add GitHub Comment" shell: bash env: - PREVIEWER_URL: "${{ inputs.server }}/preview/${{ github.repository }}/${{ github.event.issue.number }}" ADD_COMMENT_URL: "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments" - GITHUB_TOKEN: "${{ inputs.token }}" - ARTIFACT_JOB: "${{ inputs.job }}" - run: | - PREVIEWER_RESPONSE=$(curl -X POST --data-urlencode "job=${JOB}" ${PREVIEWER_URL}) - if [[ $? ]]; then - curl -H "Authorization: token ${GITHUB_TOKEN}" \ - -d '{"body": "${PREVIEWER_RESPONSE}"}' \ - ${ADD_COMMENT_URL} - else - echo $PREVIEWER_RESPONSE - fi + AUTHORIZATION_HEADER: "Authorization: token ${{ inputs.github_token }}" + PREVIEWER_RESPONSE: "${{ steps.call-previewer.outputs.previewer-response }}" + run: curl -H "${AUTHORIZATION_HEADER}" -d "{\"body\": \"${PREVIEWER_RESPONSE}\"}" ${ADD_COMMENT_URL}