From 4055fb6f28b2f8fe8839ba3d0a9d1946b64e6bba Mon Sep 17 00:00:00 2001 From: Ohad Schneider Date: Sun, 26 Nov 2023 03:41:29 +0200 Subject: [PATCH 1/5] vercel pr deploy action (#43) * vercel pr deploy action * Install recent node & pnpm * Comment with vercel deployment URL * Use pull request number (not ID) * add pr permissions * try removing issues permissions * reusable vercel deploy workflow * prod deployment * fix commit link --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> --- .github/workflows/pr-deploy.yml | 20 ++++++ .github/workflows/prod-deploy.yml | 20 ++++++ .github/workflows/reusable-deploy-vercel.yml | 68 ++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 .github/workflows/pr-deploy.yml create mode 100644 .github/workflows/prod-deploy.yml create mode 100644 .github/workflows/reusable-deploy-vercel.yml diff --git a/.github/workflows/pr-deploy.yml b/.github/workflows/pr-deploy.yml new file mode 100644 index 00000000..325f2508 --- /dev/null +++ b/.github/workflows/pr-deploy.yml @@ -0,0 +1,20 @@ +name: PR Deployment + +on: [pull_request, workflow_dispatch] + +jobs: + deploy: + permissions: + contents: read + pull-requests: write + + uses: ./.github/workflows/reusable-deploy-vercel.yml + + with: + PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }} + COMMIT_SHA: ${{ github.event.pull_request.head.sha }} + + secrets: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/prod-deploy.yml b/.github/workflows/prod-deploy.yml new file mode 100644 index 00000000..70c2531a --- /dev/null +++ b/.github/workflows/prod-deploy.yml @@ -0,0 +1,20 @@ +name: PR Deployment + +on: + workflow_dispatch: + push: + branches: + - main + +jobs: + deploy: + permissions: + contents: read + pull-requests: write + + uses: ./.github/workflows/reusable-deploy-vercel.yml + + secrets: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/reusable-deploy-vercel.yml b/.github/workflows/reusable-deploy-vercel.yml new file mode 100644 index 00000000..0a8bbc74 --- /dev/null +++ b/.github/workflows/reusable-deploy-vercel.yml @@ -0,0 +1,68 @@ +name: Vercel Deployment (reusable) + +on: + workflow_call: + inputs: + COMMIT_SHA: + required: false + type: string + PULL_REQUEST_NUMBER: + required: false + type: number + PROD: + required: false + type: boolean + default: false + secrets: + VERCEL_ORG_ID: + required: true + VERCEL_PROJECT_ID: + required: true + VERCEL_TOKEN: + required: true + +env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + VERCEL_ENVIRONMENT: ${{ inputs.PROD == true && 'production' || 'preview' }} + VERCEL_CLI_ENV_FLAG: ${{ inputs.PROD == true && '--prod' || '' }} + +jobs: + deploy: + permissions: + contents: read + pull-requests: write + + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install pnpm + run: npm install -g pnpm + + - name: Install Vercel CLI + run: npm install --global vercel@latest + + - name: Pull Vercel Environment Information + run: vercel pull --yes --environment=${{ env.VERCEL_ENVIRONMENT }} --token=${{ secrets.VERCEL_TOKEN }} + + - name: Build Project Artifacts + run: vercel build ${{ env.VERCEL_CLI_ENV_FLAG }} --token=${{ secrets.VERCEL_TOKEN }} + + - name: Deploy Project Artifacts to Vercel + run: vercel deploy ${{ env.VERCEL_CLI_ENV_FLAG }} --prebuilt --token=${{ secrets.VERCEL_TOKEN }} > /tmp/vercel-deployment-url.txt + + - name: Generate PR comment + if: ${{ inputs.PULL_REQUEST_NUMBER != 0 }} + uses: actions/github-script@v7 + with: + script: | + const fsAsync = require("fs").promises; + const deploymentUrl = await fsAsync.readFile("/tmp/vercel-deployment-url.txt", "utf8"); + + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: ${{ inputs.PULL_REQUEST_NUMBER }}, + body: `Version ${{ inputs.COMMIT_SHA }} deployed to Vercel: ${deploymentUrl}` + }); \ No newline at end of file From 77c2236ee72076005ed7b3e8acb429b9e8c4b09f Mon Sep 17 00:00:00 2001 From: Ohad Schneider Date: Sun, 26 Nov 2023 03:45:07 +0200 Subject: [PATCH 2/5] Update prod-deploy.yml --- .github/workflows/prod-deploy.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/prod-deploy.yml b/.github/workflows/prod-deploy.yml index 70c2531a..22eb48df 100644 --- a/.github/workflows/prod-deploy.yml +++ b/.github/workflows/prod-deploy.yml @@ -1,4 +1,4 @@ -name: PR Deployment +name: PROD Deployment on: workflow_dispatch: @@ -13,8 +13,11 @@ jobs: pull-requests: write uses: ./.github/workflows/reusable-deploy-vercel.yml + + with: + PROD: true secrets: VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} - VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} \ No newline at end of file + VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} From ce41e9e79a363ec984315eebb5c021551a00cdc6 Mon Sep 17 00:00:00 2001 From: Ohad Schneider Date: Sun, 26 Nov 2023 03:49:26 +0200 Subject: [PATCH 3/5] Update prod-deploy.yml --- .github/workflows/prod-deploy.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/prod-deploy.yml b/.github/workflows/prod-deploy.yml index 22eb48df..8a7bd0a2 100644 --- a/.github/workflows/prod-deploy.yml +++ b/.github/workflows/prod-deploy.yml @@ -10,7 +10,6 @@ jobs: deploy: permissions: contents: read - pull-requests: write uses: ./.github/workflows/reusable-deploy-vercel.yml From f311f236b825a4e137ae496c8c7de21b72665777 Mon Sep 17 00:00:00 2001 From: Ohad Schneider Date: Sun, 26 Nov 2023 03:51:00 +0200 Subject: [PATCH 4/5] Update reusable-deploy-vercel.yml --- .github/workflows/reusable-deploy-vercel.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/reusable-deploy-vercel.yml b/.github/workflows/reusable-deploy-vercel.yml index 0a8bbc74..8fabf31f 100644 --- a/.github/workflows/reusable-deploy-vercel.yml +++ b/.github/workflows/reusable-deploy-vercel.yml @@ -29,9 +29,6 @@ env: jobs: deploy: - permissions: - contents: read - pull-requests: write runs-on: ubuntu-latest steps: @@ -65,4 +62,4 @@ jobs: repo: context.repo.repo, issue_number: ${{ inputs.PULL_REQUEST_NUMBER }}, body: `Version ${{ inputs.COMMIT_SHA }} deployed to Vercel: ${deploymentUrl}` - }); \ No newline at end of file + }); From 6fccacc2b9d5d36c45bcc74bb9d7cb9870f82e1b Mon Sep 17 00:00:00 2001 From: Ohad Schneider Date: Sun, 26 Nov 2023 03:54:31 +0200 Subject: [PATCH 5/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3b72cfc1..da869b2e 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ --- ## 📖 **Introduction** - +123 Welcome to a centralized repository of links and resources dedicated to Israel. Utilizing the collaborative power of Git, our goal is to galvanize support for Israel, especially during challenging moments. ---