forked from ubiquity/pay.ubq.fi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ubiquity#112 from whilefoo/test
Reusable deploy
- Loading branch information
Showing
2 changed files
with
21 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
|
@@ -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 }} |