Skip to content

Commit

Permalink
Merge pull request #747 from whilefoo/reusable-deploy
Browse files Browse the repository at this point in the history
Reusable deploy
  • Loading branch information
0x4007 authored Aug 7, 2023
2 parents a80eec5 + 9071bc6 commit 611472a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 78 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ jobs:
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 ./packages/dapp && zip -r pull-request.zip ./dist && cp pull-request.zip ../../pr
cd ./packages/dapp/dist && zip -r ../../../pr/pull-request.zip ./*
- uses: actions/upload-artifact@v3
with:
name: pr
Expand Down
88 changes: 11 additions & 77 deletions .github/workflows/continuous-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,81 +7,15 @@ on:
- completed

jobs:
deploy:
name: Deploy
runs-on: ubuntu-22.04
deploy-to-cloudflare:
name: Deploy to Cloudflare Pages
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout repository
uses: actions/[email protected]

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

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

- name: "Download Artifact"
uses: actions/[email protected]
with:
script: |
const fs = require("fs");
const downloadArtifact = require('${{ github.workspace }}/utils/download-artifact.js');
const workflow_run_id = '${{ github.event.workflow_run.id }}';
const workspace = '${{ github.workspace }}';
downloadArtifact({github, context, fs, workflow_run_id, workspace})
- name: Extract Artifact
run: unzip pr.zip && unzip pull-request.zip && ls

- name: Deploy Cloudflare
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
REPOSITORY: ${{ github.repository }}
PRODUCTION_BRANCH: "development"
OUTPUT_DIRECTORY: "dist"
run: |
IFS='/' read -ra fields <<< "$REPOSITORY"
projectName="${fields[1]}"
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
wrangler pages publish "$OUTPUT_DIRECTORY" --project-name "$projectName" > ./deployments.log
ls -la
cat deployments.log
# - name: Deploy Railway
# run: |
# cd dist
# npm i -g @railway/cli
# RAILWAY_TOKEN=${{ secrets.RAILWAY_API_TOKEN }} railway link ${{ secrets.RAILWAY_PROJECT_ID }}
# RAILWAY_TOKEN=${{ secrets.RAILWAY_API_TOKEN }} railway up

- name: Get UbiquiBot Token
uses: tibdex/[email protected]
id: get_installation_token
with:
app_id: ${{ secrets.UBIQUITY_BOUNTY_BOT_APP_ID }}
private_key: ${{ secrets.UBIQUITY_BOUNTY_BOT_PRIVATE_KEY }}

- name: Save UbiquiBot Token
env:
TOKEN: ${{ steps.get_installation_token.outputs.token }}
run: |
echo "The generated token is masked: ${TOKEN}"
- name: Deploy Comment as UbiquiBot
uses: actions/github-script@v6
with:
github-token: ${{ steps.get_installation_token.outputs.token }}
script: |
const fs = require("fs");
const printDeploymentsLog = require('${{ github.workspace }}/utils/print-deployments-logs.js');
await printDeploymentsLog({github, context, fs});
uses: ubiquity/.github/.github/workflows/deploy.yml@main
permissions:
contents: read
pull-requests: write
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 }}

1 comment on commit 611472a

@ubiquibot
Copy link

@ubiquibot ubiquibot bot commented on 611472a Aug 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.