From 415f2e46e2a1a3c10119208ffc50718db5b9060b Mon Sep 17 00:00:00 2001 From: EresDev Date: Tue, 2 Apr 2024 15:35:51 +0500 Subject: [PATCH] fix: prevent deploy to production on open PR --- action.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index c261c8e..8258e25 100644 --- a/action.yml +++ b/action.yml @@ -50,11 +50,13 @@ runs: const items = response.data.items if (items.length < 1) { console.error('No PRs found') - return + return {forcePreviewDeploy: false, pullRequestNumber: null } } const pullRequestNumber = items[0].number + const forcePreviewDeploy = pullRequestNumber > 0 && items[0].pull_request.merged_at == null console.info("Pull request number is", pullRequestNumber) - return pullRequestNumber + console.info("forcePreviewDeploy", forcePreviewDeploy) + return {forcePreviewDeploy: forcePreviewDeploy, pullRequestNumber: pullRequestNumber } - name: Download build artifact uses: dawidd6/action-download-artifact@v3 @@ -64,7 +66,7 @@ runs: run_id: ${{ inputs.workflow_run_id }} - name: Deploy to Cloudflare - run: bash ../../_actions/ubiquity/cloudflare-deploy-action/main/.github/cloudflare-deploy.sh "${{ inputs.repository }}" "${{ inputs.production_branch }}" "${{ inputs.output_directory }}" "${{ inputs.current_branch }}" + run: bash ../../_actions/ubiquity/cloudflare-deploy-action/main/.github/cloudflare-deploy.sh "${{ inputs.repository }}" "${{ inputs.production_branch }}" "${{ inputs.output_directory }}" "${{ fromJSON(steps.pr.outputs.result).forcePreviewDeploy && format('{0}/{1}', github.repository_owner, inputs.current_branch) || inputs.current_branch }}" shell: bash env: CLOUDFLARE_ACCOUNT_ID: ${{ inputs.cloudflare_account_id }} @@ -78,5 +80,5 @@ runs: yarn tsx src/index.ts \ --deployment_output "${{ env.DEPLOYMENT_OUTPUT }}" \ --repository "${{ inputs.repository }}" \ - --pull_request_number "${{ steps.pr.outputs.result }}" \ + --pull_request_number "${{ fromJSON(steps.pr.outputs.result).pullRequestNumber }}" \ --commit_sha "${{ inputs.commit_sha }}"