From 0f1d6048931e3a055eeb1775353ac75113c9cb0d Mon Sep 17 00:00:00 2001 From: Alex Gabites Date: Wed, 13 Sep 2023 20:25:13 +1200 Subject: [PATCH 1/5] Add `workflow_dispatch` to all workflows --- .github/workflows/benchmark.yaml | 1 + .github/workflows/ci.yaml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/benchmark.yaml b/.github/workflows/benchmark.yaml index bbf8825..555fd91 100644 --- a/.github/workflows/benchmark.yaml +++ b/.github/workflows/benchmark.yaml @@ -4,6 +4,7 @@ on: push: branches: - "main" + workflow_dispatch: jobs: deploy-draft-original: diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f4153f9..c38f5d3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -4,6 +4,7 @@ on: push: branches-ignore: - "master" + workflow_dispatch: jobs: deploy-draft-new: From ad0c34f3cb8b1e314e281114f4c766dcd531fbf3 Mon Sep 17 00:00:00 2001 From: Alex Gabites Date: Wed, 13 Sep 2023 20:25:22 +1200 Subject: [PATCH 2/5] Fix CI workflow ignore branch --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c38f5d3..9c5d497 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -3,7 +3,7 @@ name: CI on: push: branches-ignore: - - "master" + - "main" workflow_dispatch: jobs: From b8a2fa29ec5cb8e0dad71e117f47b9e312cf52b0 Mon Sep 17 00:00:00 2001 From: Alex Gabites Date: Wed, 13 Sep 2023 20:26:57 +1200 Subject: [PATCH 3/5] Use checked out action for workflows --- .github/workflows/benchmark.yaml | 14 ++++++++++---- .github/workflows/ci.yaml | 10 ++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.github/workflows/benchmark.yaml b/.github/workflows/benchmark.yaml index 555fd91..6f25fac 100644 --- a/.github/workflows/benchmark.yaml +++ b/.github/workflows/benchmark.yaml @@ -58,19 +58,22 @@ jobs: echo "NETLIFY_PROD_URL: ${{ steps.netlify.outputs.NETLIFY_PROD_URL }}" deploy-draft-new: - name: draft via South-Paw/action-netlify-cli@main + name: draft via South-Paw/action-netlify-cli runs-on: ubuntu-latest needs: - deploy-draft-original - deploy-prod-original steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Generate HTML document run: | mkdir -p example echo -e "
$(date -u)\n$GITHUB_SHA\n$GITHUB_REF
" > example/index.html - name: Deploy draft to Netlify - uses: South-Paw/action-netlify-cli@main + uses: ./ id: netlify with: args: 'deploy --json --dir \"./example\" --message \"draft [${{ github.sha }}]\"' @@ -86,19 +89,22 @@ jobs: echo "NETLIFY_PROD_URL: ${{ steps.netlify.outputs.NETLIFY_PROD_URL }}" deploy-prod-new: - name: production via South-Paw/action-netlify-cli@main + name: production via South-Paw/action-netlify-cli runs-on: ubuntu-latest needs: - deploy-draft-original - deploy-prod-original steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Generate HTML document run: | mkdir -p example echo -e "
$(date -u)\n$GITHUB_SHA\n$GITHUB_REF
" > example/index.html - name: Deploy to Netlify - uses: South-Paw/action-netlify-cli@main + uses: ./ id: netlify with: args: 'deploy --json --prod --dir \"./example\" --message \"production [${{ github.sha }}]\"' diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9c5d497..619440e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -11,13 +11,16 @@ jobs: name: draft runs-on: ubuntu-latest steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Generate HTML document run: | mkdir -p example echo -e "
$(date -u)\n$GITHUB_SHA\n$GITHUB_REF
" > example/index.html - name: Deploy draft to Netlify - uses: South-Paw/action-netlify-cli@main + uses: ./ id: netlify with: args: 'deploy --json --dir \"./example\" --message \"draft [${{ github.sha }}]\"' @@ -36,13 +39,16 @@ jobs: name: production runs-on: ubuntu-latest steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Generate HTML document run: | mkdir -p example echo -e "
$(date -u)\n$GITHUB_SHA\n$GITHUB_REF
" > example/index.html - name: Deploy to Netlify - uses: South-Paw/action-netlify-cli@main + uses: ./ id: netlify with: args: 'deploy --prod --json --dir \"./example\" --message \"production [${{ github.sha }}]\"' From 39cf4cff917a89251594592ebf7cef3b887c4ac3 Mon Sep 17 00:00:00 2001 From: Alex Gabites Date: Wed, 13 Sep 2023 20:27:08 +1200 Subject: [PATCH 4/5] Change description --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 7e93c3f..c83582b 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ name: "Netlify CLI" -description: "Wraps the Netlify CLI and offers access to deploy outputs" +description: "Fast Netlify CLI wrapper with output" author: "Alex Gabites " branding: color: purple From 2a090aa136113890938353b4859a26864d1215d3 Mon Sep 17 00:00:00 2001 From: Alex Gabites Date: Wed, 13 Sep 2023 20:28:50 +1200 Subject: [PATCH 5/5] 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 }}