Skip to content

Commit

Permalink
[CI] Deploy CFPages app on push (#14)
Browse files Browse the repository at this point in the history
* [CI] Deploy CFPages app on push

* Run build

* Rm dist

* Add deployment envs

* Permissions

* Bump to v2

* Add env

* Add env url

* Update env.

* Update garbage
  • Loading branch information
MNThomson committed Jan 18, 2023
1 parent 8a4b31e commit e6e93e7
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 1 deletion.
89 changes: 89 additions & 0 deletions .github/workflows/deploy.yml
@@ -0,0 +1,89 @@
name: Deploy

on:
push:
branches:
- master
pull_request:

env:
env_name: ${{ github.ref != 'refs/heads/master' && format('{0}-{1}', 'pr', github.event.number) || 'prod' }}
cf_name: ${{ github.ref != 'refs/heads/master' && format('{0}-{1}', 'pr', github.event.number) || 'main' }}

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
pull-requests: write
environment:
name: ${{ github.ref != 'refs/heads/master' && format('{0}-{1}', 'pr', github.event.number) || 'prod' }}
url: ${{ github.ref != 'refs/heads/master' && format('{0}-{1}{2}', 'https://pr', github.event.number, '.containerflare.pages.dev') || 'https://cfcr.dev' }}
name: Deploy to Cloudflare Pages
steps:
- name: Start deployment
uses: bobheadxi/deployments@v1
id: deployment
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: ${{ env.env_name }}

- name: Checkout code
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
cache: "npm"

- name: Initialize npm
run: npm ci

- name: Initialize npm
run: npm run build

- name: Publish to Cloudflare Pages
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: containerflare
directory: ./dist
branch: ${{ env.cf_name }}
id: publish

- name: Update deployment status
uses: bobheadxi/deployments@v1
if: always()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
env: ${{ env.env_name }}
env_url: ${{ github.ref != 'refs/heads/master' && format('{0}-{1}{2}', 'https://pr', github.event.number, '.containerflare.pages.dev') || 'https://cfcr.dev' }}
debug: true

- name: Find PR comment
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ github.event.number }}
comment-author: "github-actions[bot]"
body-includes: "preview of this pull request"
if: github.event_name == 'pull_request'

- name: Comment on PR
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.number }}
body: |
A preview of this pull request is ready!
See it at ${{ github.ref != 'refs/heads/master' && format('{0}-{1}{2}', 'https://pr', github.event.number, '.containerflare.pages.dev') || 'https://cfcr.dev' }}
View the deploy log at https://github.com/MNThomson/containerflare/actions/runs/${{ github.run_id}}
edit-mode: replace
if: github.event_name == 'pull_request'
5 changes: 4 additions & 1 deletion .github/workflows/lint.yml
Expand Up @@ -18,8 +18,11 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup nodejs
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
cache: "npm"

- name: Initialize npm
run: npm ci
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/pull_request_cleanup.yml
@@ -0,0 +1,18 @@
name: Pull Request Cleanup

on:
pull_request_target:
types:
- closed

jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Delete deployment
uses: bobheadxi/deployments@v1
with:
step: delete-env
token: ${{ github.token }}
env: pr-${{ github.event.number }}
desc: Deployment was pruned

0 comments on commit e6e93e7

Please sign in to comment.