From 2a090aa136113890938353b4859a26864d1215d3 Mon Sep 17 00:00:00 2001 From: Alex Gabites Date: Wed, 13 Sep 2023 20:28:50 +1200 Subject: [PATCH] Remove deploy specific outputs from action Added a recipe for parsing when using the `--json` flag --- .github/workflows/benchmark.yaml | 12 --------- .github/workflows/ci.yaml | 6 ----- README.md | 46 ++++++++++++++++++++++++++------ action.yml | 9 ------- 4 files changed, 38 insertions(+), 35 deletions(-) diff --git a/.github/workflows/benchmark.yaml b/.github/workflows/benchmark.yaml index 6f25fac..faf3514 100644 --- a/.github/workflows/benchmark.yaml +++ b/.github/workflows/benchmark.yaml @@ -28,9 +28,6 @@ jobs: - name: Action outputs run: | echo "NETLIFY_OUTPUT: ${{ steps.netlify.outputs.NETLIFY_OUTPUT }}" - echo "NETLIFY_LOGS_URL: ${{ steps.netlify.outputs.NETLIFY_LOGS_URL }}" - echo "NETLIFY_DRAFT_URL: ${{ steps.netlify.outputs.NETLIFY_DRAFT_URL }}" - echo "NETLIFY_PROD_URL: ${{ steps.netlify.outputs.NETLIFY_PROD_URL }}" deploy-prod-original: name: production via netlify/actions/cli@master @@ -53,9 +50,6 @@ jobs: - name: Action outputs run: | echo "NETLIFY_OUTPUT: ${{ steps.netlify.outputs.NETLIFY_OUTPUT }}" - echo "NETLIFY_LOGS_URL: ${{ steps.netlify.outputs.NETLIFY_LOGS_URL }}" - echo "NETLIFY_DRAFT_URL: ${{ steps.netlify.outputs.NETLIFY_DRAFT_URL }}" - echo "NETLIFY_PROD_URL: ${{ steps.netlify.outputs.NETLIFY_PROD_URL }}" deploy-draft-new: name: draft via South-Paw/action-netlify-cli @@ -84,9 +78,6 @@ jobs: - name: Action outputs run: | echo "NETLIFY_OUTPUT: ${{ steps.netlify.outputs.NETLIFY_OUTPUT }}" - echo "NETLIFY_LOGS_URL: ${{ steps.netlify.outputs.NETLIFY_LOGS_URL }}" - echo "NETLIFY_DRAFT_URL: ${{ steps.netlify.outputs.NETLIFY_DRAFT_URL }}" - echo "NETLIFY_PROD_URL: ${{ steps.netlify.outputs.NETLIFY_PROD_URL }}" deploy-prod-new: name: production via South-Paw/action-netlify-cli @@ -115,6 +106,3 @@ jobs: - name: Action outputs run: | echo "NETLIFY_OUTPUT: ${{ steps.netlify.outputs.NETLIFY_OUTPUT }}" - echo "NETLIFY_LOGS_URL: ${{ steps.netlify.outputs.NETLIFY_LOGS_URL }}" - echo "NETLIFY_DRAFT_URL: ${{ steps.netlify.outputs.NETLIFY_DRAFT_URL }}" - echo "NETLIFY_PROD_URL: ${{ steps.netlify.outputs.NETLIFY_PROD_URL }}" diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 619440e..181ce44 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -31,9 +31,6 @@ jobs: - name: Action outputs run: | echo "NETLIFY_OUTPUT: ${{ steps.netlify.outputs.NETLIFY_OUTPUT }}" - echo "NETLIFY_LOGS_URL: ${{ steps.netlify.outputs.NETLIFY_LOGS_URL }}" - echo "NETLIFY_DRAFT_URL: ${{ steps.netlify.outputs.NETLIFY_DRAFT_URL }}" - echo "NETLIFY_PROD_URL: ${{ steps.netlify.outputs.NETLIFY_PROD_URL }}" deploy-prod-new: name: production @@ -59,6 +56,3 @@ jobs: - name: Action outputs run: | echo "NETLIFY_OUTPUT: ${{ steps.netlify.outputs.NETLIFY_OUTPUT }}" - echo "NETLIFY_LOGS_URL: ${{ steps.netlify.outputs.NETLIFY_LOGS_URL }}" - echo "NETLIFY_DRAFT_URL: ${{ steps.netlify.outputs.NETLIFY_DRAFT_URL }}" - echo "NETLIFY_PROD_URL: ${{ steps.netlify.outputs.NETLIFY_PROD_URL }}" diff --git a/README.md b/README.md index a8ebad8..2fe4f47 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,6 @@ This action usually completes in under a minute (and in best cases, 30s). The following outputs will be available from a step that uses this action: - `NETLIFY_OUTPUT`, the full stdout from the run of the `netlify` command -- `NETLIFY_LOGS_URL`, the URL where the logs from the deploy can be found -- `NETLIFY_DRAFT_URL`, the URL of the draft site that Netlify provides -- `NETLIFY_PROD_URL`, the URL of the "real" site, set only if `--prod` was passed ## Recipes @@ -33,11 +30,10 @@ jobs: # build your site for deployment... in this case the `public` folder is being deployed - name: Publish - uses: South-Paw/action-netlify-cli@1.0.1 + uses: South-Paw/action-netlify-cli@v2 id: netlify with: - # be sure to escape any double quotes with a backslash and note that the --json - # flag has been passed when deploying - if you want the outputs to work you'll need to include it + # be sure to escape any double quotes with a backslash args: 'deploy --json --dir \"./public\" --message \"draft [${{ github.sha }}]\"' env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} @@ -64,9 +60,10 @@ jobs: # ... steps to build your site for deployment - name: Deploy to Netlify - uses: South-Paw/action-netlify-cli@1.0.1 + uses: South-Paw/action-netlify-cli@v2 id: netlify with: + # note that the --json flag has been passed so we can parse outputs args: deploy --json --prod --dir './public' --message 'production [${{ github.sha }}]' env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} @@ -80,7 +77,40 @@ jobs: step: finish status: ${{ job.status }} deployment_id: ${{ steps.deployment.outputs.deployment_id }} - env_url: ${{ steps.netlify.outputs.NETLIFY_PROD_URL }} + env_url: ${{ fromJson(steps.netlify.outputs.NETLIFY_OUTPUT).url }} +``` + +### Parse `--json` flag + +```yml +on: [push] +jobs: + publish: + runs-on: ubuntu-latest + steps: + # ... steps to build your site for deployment + + - name: Deploy to Netlify + uses: South-Paw/action-netlify-cli@v2 + id: netlify + with: + # note that the --json flag has been passed so we can parse outputs + args: deploy --json --prod --dir './public' --message 'production [${{ github.sha }}]' + env: + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} + + # You can parse the `NETLIFY_OUTPUT` output with `fromJson` function for the following information: + - name: Parse NETLIFY_OUTPUT JSON + run: | + echo "The URL where the logs from the deploy can be found" + echo "${{ fromJson(steps.netlify.outputs.NETLIFY_OUTPUT).logs }}" + echo "" + echo "the URL of the draft site that Netlify provides" + echo "${{ fromJson(steps.netlify.outputs.NETLIFY_OUTPUT).deploy_url }}" + echo "" + echo "the URL of the "real" site, set only if `--prod` was passed" + echo "${{ fromJson(steps.netlify.outputs.NETLIFY_OUTPUT).url }}" ``` ## Issues and Bugs diff --git a/action.yml b/action.yml index c83582b..33c61f3 100644 --- a/action.yml +++ b/action.yml @@ -18,12 +18,3 @@ outputs: NETLIFY_OUTPUT: description: "Raw Netlify CLI output message" value: ${{ steps.script.outputs.NETLIFY_OUTPUT }} - NETLIFY_LOGS_URL: - description: "URL to Netlify deployment logs" - value: ${{ fromJson(steps.script.outputs.NETLIFY_OUTPUT).logs }} - NETLIFY_DRAFT_URL: - description: "URL to draft site" - value: ${{ fromJson(steps.script.outputs.NETLIFY_OUTPUT).deploy_url }} - NETLIFY_PROD_URL: - description: "URL to production site" - value: ${{ fromJson(steps.script.outputs.NETLIFY_OUTPUT).url }}