Skip to content

Commit

Permalink
Merge pull request #4 from elecordapp/github-actions
Browse files Browse the repository at this point in the history
Deploy to Cloudflare pages
  • Loading branch information
hazzuk authored Dec 8, 2024
2 parents 2c05041 + 436e0aa commit db10dd3
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 93 deletions.
94 changes: 92 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build
on:
pull_request: {}
push:
branches: [develop, master]
branches: [release, master]
merge_group:
types: [checks_requested]
# develop pushes and repository_dispatch handled in build_develop.yaml
Expand Down Expand Up @@ -59,4 +59,94 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: webapp
path: dist/elecord.tar.gz
path: dist/elecord.tar.gz

deploy:
needs: build
name: Deploy webapp
runs-on: ubuntu-24.04
permissions:
pull-requests: write
steps:
# Download and extract the build folder
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: webapp
path: .

- name: Extract tarball
run: tar -xvzf elecord.tar.gz

- name: Move to dist
run: mv elecord-*/ dist

# Set the Cloudflare pages branch name
# - PR to master : test
# - Push to master : dev
# - PR to release : preview
# - Push to release : main (Production environment)
- name: Set Pages branch
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
if [[ "${{ github.event.pull_request.base.ref }}" == "master" ]]; then
echo "cf_branch=test" >> $GITHUB_ENV
elif [[ "${{ github.event.pull_request.base.ref }}" == "release" ]]; then
echo "cf_branch=preview" >> $GITHUB_ENV
fi
elif [[ "${{ github.event_name }}" == "push" ]]; then
if [[ "${{ github.ref_name }}" == "master" ]]; then
echo "cf_branch=dev" >> $GITHUB_ENV
elif [[ "${{ github.ref_name }}" == "release" ]]; then
echo "cf_branch=main" >> $GITHUB_ENV
fi
fi
# Deploy to Cloudflare Pages (using wrangler)
- name: Deploy to Cloudflare Pages
id: cf
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_PAGES_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy dist --project-name=elecord-web --branch=${{ env.cf_branch }}

# Update PR status comment with deployment URL
- name: Update status comment (Failure)
if: ${{ github.event_name == 'pull_request' && failure() }}
uses: thollander/actions-comment-pull-request@v3
with:
message: |
## Cloudflare Pages deployment
| **Latest commit** | <code>${{ github.event.pull_request.head.sha || github.sha }}</code> |
|-------------------|:-:|
| **Status** | ❌ Failure. Check workflow logs for details |
| **Preview URL** | Not available |
pr-number: ${{ github.event.pull_request.number }}
comment-tag: CFPages-deployment
reactions: -1
mode: recreate

# When deploying to the preview branch, add the preview URL
- name: Add preview URL
run: |
if [[ "${{ env.cf_branch }}" == "preview" ]]; then
echo -e "cf_preview=https://preview.elecord.app\n" >> $GITHUB_ENV
fi
- name: Update status comment (Success)
if: ${{ github.event_name == 'pull_request' && success() }}
uses: thollander/actions-comment-pull-request@v3
with:
message: |
## Cloudflare Pages deployment
| **Latest commit** | <code>${{ github.event.pull_request.head.sha || github.sha }}</code> |
|-------------------|:-:|
| **Status** | ✅ Deployed! |
| **URL** | ${{ env.cf_preview }}${{ steps.cf.outputs.deployment-url != '' && steps.cf.outputs.deployment-url || 'Not available' }} |
pr-number: ${{ github.event.pull_request.number }}
comment-tag: CFPages-deployment
reactions: rocket
mode: recreate
91 changes: 0 additions & 91 deletions .github/workflows/deploy.yml

This file was deleted.

0 comments on commit db10dd3

Please sign in to comment.