Skip to content

Commit

Permalink
Merge pull request ubiquity#112 from whilefoo/test
Browse files Browse the repository at this point in the history
Reusable deploy
  • Loading branch information
rndquu authored Aug 8, 2023
2 parents ea8c586 + 4cd65b0 commit c9e7ed9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 82 deletions.
25 changes: 13 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@ jobs:
- name: Add commit SHA file to build folder
run: echo -n $(echo "${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}" | cut -c1-7) > static/commit.txt

- name: Archive build
uses: actions/upload-artifact@v3
- name: Prepare Deployment Artifact
env:
EVENT_NAME: ${{github.event_name}}
PR_NUMBER: ${{ github.event.number }}
SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
run: |
echo "event_name=$EVENT_NAME,pr_number=$PR_NUMBER,sha=$SHA"
mkdir -p ./pr
echo "event_name=$EVENT_NAME,pr_number=$PR_NUMBER,sha=$SHA," > ./pr/pr_number
cd ./static && zip -r ../pr/pull-request.zip ./*
- uses: actions/upload-artifact@v3
with:
name: pr
path: static

- name: Create a file with PR number
run: echo -n ${{ github.event.number }} > pr-num.txt

- name: Upload the PR number
uses: actions/upload-artifact@v2
with:
name: pr-num
path: pr-num.txt
path: pr/
78 changes: 8 additions & 70 deletions .github/workflows/continuous-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Cloudflare Preview Deployment
name: Deploy to Cloudflare Pages

on:
workflow_run:
Expand All @@ -9,75 +9,13 @@ on:
jobs:
deploy-to-cloudflare:
name: Deploy to Cloudflare Pages
runs-on: ubuntu-22.04
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: ubiquity/.github/.github/workflows/deploy.yml@main
permissions:
contents: read
pull-requests: write

if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "18.14.1"

- name: Wrangler Install
run: npm install -g wrangler

- name: Download build artifact
uses: dawidd6/action-download-artifact@v2
with:
name: pr
workflow: build.yml
path: pr

- name: Publish to Cloudflare
id: publish-to-cloudflare
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
REPOSITORY: ${{ github.repository }}
PRODUCTION_BRANCH: "development"
OUTPUT_DIRECTORY: "pr"
run: |
IFS='/' read -ra fields <<< "$REPOSITORY"
projectName="${fields[1]}"
projectName=$(echo $projectName | sed 's/\./-/g')
echo $projectName
wrangler pages project list > project_list.txt
if grep -q $projectName project_list.txt; then
echo "Project found"
else
echo "Project not found"
wrangler pages project create "$projectName" --production-branch "$PRODUCTION_BRANCH"
fi
echo DEPLOY_URL=$(wrangler pages publish "$OUTPUT_DIRECTORY" --project-name "$projectName" | grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*") >> $GITHUB_OUTPUT
- name: Print deploy URL
run: echo ${{ steps.publish-to-cloudflare.outputs.DEPLOY_URL }}

- name: Download PR number artifact
uses: dawidd6/action-download-artifact@v2
with:
name: pr-num
workflow: build.yml
path: pr-num

- name: Read PR number from file
id: pr-num-reader
uses: juliangruber/[email protected]
with:
path: pr-num/pr-num.txt

- name: Print PR number from file
run: echo ${{ steps.pr-num-reader.outputs.content }}

- name: Comment PR
# PR number exists only on "pull_request" event so comment only when it exists
if: ${{ steps.pr-num-reader.outputs.content }}
uses: thollander/actions-comment-pull-request@v2
with:
message: ${{ steps.publish-to-cloudflare.outputs.DEPLOY_URL }}
pr_number: ${{ steps.pr-num-reader.outputs.content }}
secrets:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
UBIQUITY_BOUNTY_BOT_APP_ID: ${{ secrets.UBIQUITY_BOUNTY_BOT_APP_ID }}
UBIQUITY_BOUNTY_BOT_PRIVATE_KEY: ${{ secrets.UBIQUITY_BOUNTY_BOT_PRIVATE_KEY }}

0 comments on commit c9e7ed9

Please sign in to comment.