From 5d04b3ab4137056a3a803406ada23b40d045bf2a Mon Sep 17 00:00:00 2001 From: Neil Hanlon Date: Mon, 29 Jul 2024 12:39:45 -0400 Subject: [PATCH] feat: support project_directory for preview action (fixes #49) Signed-off-by: Neil Hanlon --- preview/action.yml | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/preview/action.yml b/preview/action.yml index e8aef4c..7937f2f 100644 --- a/preview/action.yml +++ b/preview/action.yml @@ -2,6 +2,10 @@ name: 'Branch Preview' description: 'Preview Fastly Service' inputs: + project_directory: + description: 'Directory of the project to build, relative to the repository root.' + required: false + default: './' fastly-api-token: description: 'The Fastly API token to use for interacting with Fastly API' required: true @@ -20,46 +24,60 @@ outputs: runs: using: "composite" steps: - - uses: actions/checkout@v4 # Download Fastly CLI - name: Set up Fastly CLI uses: fastly/compute-actions/setup@v5 with: token: ${{ inputs.github-token }} - cli_version: '10.8.4' + cli_version: 'latest' - run: yarn + working-directory: ${{ inputs.project_directory }} shell: bash # Create a new Fastly Service name with the PR number appended - name: Set service-name id: service-name + working-directory: ${{ inputs.project_directory }} run: echo "SERVICE_NAME=$(yq '.name' fastly.toml)-${{ github.event.number }}" >> "$GITHUB_OUTPUT" shell: bash # Delete the Fastly Service - if: github.event.action == 'closed' + working-directory: ${{ inputs.project_directory }} run: fastly service delete --quiet --service-name ${{ steps.service-name.outputs.SERVICE_NAME }} --force --token ${{ inputs.fastly-api-token }} || true shell: bash + env: + fastly_api_token: ${{ inputs.fastly-api-token }} # Deploy to Fastly and let Fastly choose a subdomain of edgecompute.app to attach to the service - if: github.event.action != 'closed' + working-directory: ${{ inputs.project_directory }} run: | fastly compute publish --verbose -i --token ${{ inputs.fastly-api-token }} --service-name ${{ steps.service-name.outputs.SERVICE_NAME }} shell: bash + env: + fastly_api_token: ${{ inputs.fastly-api-token }} # Retrieve the newly created domain for the service and add it to the pull-request summary - if: github.event.action != 'closed' + working-directory: ${{ inputs.project_directory }} run: fastly domain list --quiet --version latest --json --service-name="${{ steps.service-name.outputs.SERVICE_NAME }}" --token ${{ inputs.fastly-api-token }} | jq -r '.[0].Name' shell: bash + env: + FASTLY_API_TOKEN: ${{ inputs.fastly-api-token }} - if: github.event.action != 'closed' + working-directory: ${{ inputs.project_directory }} name: Set domain shell: bash id: domain run: echo "DOMAIN=$(fastly domain list --quiet --version latest --json --service-name="${{ steps.service-name.outputs.SERVICE_NAME }}" --token ${{ inputs.fastly-api-token }} | jq -r '.[0].Name')" >> "$GITHUB_OUTPUT" + env: + FASTLY_API_TOKEN: ${{ inputs.fastly-api-token }} - if: github.event.action != 'closed' + working-directory: ${{ inputs.project_directory }} shell: bash name: Add domain to summary run: echo 'This pull-request has been deployed to Fastly and is available at 🚀' >> $GITHUB_STEP_SUMMARY