-
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.
- Loading branch information
1 parent
7f5f618
commit 6bf56b9
Showing
2 changed files
with
170 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: Deploy to production | ||
|
||
env: | ||
PROJECT_NAME: rustlings | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- ".github/workflows/deploy.yml" | ||
- "package.json" | ||
- "tsconfig.json" | ||
- "astro.config.ts" | ||
- "src/**" | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- uses: oven-sh/setup-bun@v1 | ||
- name: Install Deps | ||
run: bun install | ||
|
||
- name: Build | ||
run: bun run build | ||
|
||
- name: Deploy | ||
uses: cloudflare/wrangler-action@v3 | ||
# env: | ||
# YOUR_SECRET: ${{ secrets.YOUR_SECRET }} | ||
# YOUR_OTHER_SECRET: ${{ secrets.YOUR_OTHER_SECRET }} | ||
with: | ||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | ||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | ||
command: pages deploy ./dist --project-name "${{ env.PROJECT_NAME }}" | ||
# secrets: | | ||
# YOUR_SECRET | ||
# YOUR_OTHER_SECRET |
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 |
---|---|---|
@@ -0,0 +1,128 @@ | ||
#################### 🚧 WARNING: READ THIS BEFORE USING THIS FILE 🚧 #################### | ||
# | ||
# | ||
# | ||
# IF YOU DON'T KNOW WHAT YOU'RE DOING, YOU CAN EASILY LEAK SECRETS BY USING A | ||
# `pull_request_target` WORKFLOW INSTEAD OF `pull_request`! SERIOUSLY, DO NOT | ||
# BLINDLY COPY AND PASTE THIS FILE WITHOUT UNDERSTANDING THE FULL IMPLICATIONS | ||
# OF WHAT YOU'RE DOING! WE HAVE TESTED THIS FOR OUR OWN USE CASES, WHICH ARE | ||
# NOT NECESSARILY THE SAME AS YOURS! WHILE WE AREN'T EXPOSING ANY OF OUR SECRETS, | ||
# ONE COULD EASILY DO SO BY MODIFYING OR ADDING A STEP TO THIS WORKFLOW! | ||
# | ||
# | ||
# | ||
#################### 🚧 WARNING: READ THIS BEFORE USING THIS FILE 🚧 #################### | ||
|
||
name: Preview Deployment | ||
on: | ||
pull_request_target: | ||
types: | ||
- opened | ||
- synchronize | ||
- closed | ||
|
||
# cancel in-progress runs on new commits to same PR (github.event.number) | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.number || github.sha }} | ||
cancel-in-progress: true | ||
|
||
env: | ||
PROJECT_NAME: rustlings | ||
|
||
jobs: | ||
deploy-preview: | ||
if: ${{ github.event.action != 'closed' }} | ||
permissions: | ||
contents: read | ||
pull-requests: write | ||
deployments: write | ||
runs-on: ubuntu-latest | ||
name: Deploy Preview to Cloudflare Pages | ||
env: | ||
BRANCH_NAME: preview-${{ github.head_ref }} | ||
ACTION_RUN: ${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: "recursive" | ||
ref: ${{ github.event.pull_request.head.ref }} | ||
repository: ${{ github.event.pull_request.head.repo.full_name }} | ||
|
||
- name: Create comment | ||
id: comment | ||
uses: peter-evans/create-or-update-comment@v4 | ||
with: | ||
issue-number: ${{ github.event.pull_request.number }} | ||
comment-author: 'github-actions[bot]' | ||
body: | | ||
## ⚡ Cloudflare Pages Deployment | ||
| Name | Status | Preview | | ||
| :--- | :----- | :------ | | ||
| ${{env.BRANCH_NAME}} | 🔨 Building ([Logs](${{env.ACTION_RUN}})) | waiting... | | ||
# Build Rust Page | ||
- uses: oven-sh/setup-bun@v1 | ||
- name: Install Deps | ||
run: bun install | ||
- name: Build | ||
run: bun run build | ||
|
||
# Deploy steps | ||
- name: Deploy | ||
id: deploy | ||
uses: cloudflare/wrangler-action@v3 | ||
with: | ||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | ||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | ||
command: pages deploy ./dist --project-name "${{ env.PROJECT_NAME }}" --branch "${{ env.BRANCH_NAME }}" | ||
|
||
- name: Extract hash from CF url Deploy | ||
run: | | ||
url_hash=$(echo "${{ steps.deploy.outputs.deployment-url }}" | sed -n 's|https://\([^.]*\).${{env.PROJECT_NAME}}.*|\1|p') | ||
echo "SHA_SHORT=$url_hash" >> $GITHUB_ENV | ||
- name: Create comment | ||
uses: peter-evans/create-or-update-comment@v4 | ||
with: | ||
issue-number: ${{ github.event.pull_request.number }} | ||
comment-id: ${{ steps.comment.outputs.comment-id }} | ||
edit-mode: replace | ||
body: | | ||
## ⚡ Cloudflare Pages Deployment | ||
| Name | Status | Preview | | ||
| :--- | :----- | :------ | | ||
| ${{env.BRANCH_NAME}} | ✅ Ready ([Logs](${{env.ACTION_RUN}})) | [${{env.SHA_SHORT}}](${{ steps.deploy.outputs.deployment-url }}) | | ||
# remove-preview: | ||
# if: ${{ github.event.action == "closed" }} | ||
# permissions: | ||
# contents: read | ||
# pull-requests: write | ||
# deployments: write | ||
# runs-on: ubuntu-latest | ||
# name: Remove Preview of Cloudflare Pages | ||
# steps: | ||
# - uses: actions/checkout@v3 | ||
# with: | ||
# submodules: "recursive" | ||
# ref: ${{ github.event.pull_request.head.ref }} | ||
# repository: ${{ github.event.pull_request.head.repo.full_name }} | ||
|
||
# - name: Deploy | ||
# id: deploy | ||
# uses: cloudflare/wrangler-action@v3 | ||
# with: | ||
# apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | ||
# accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | ||
# command: pages --project-name=homepage --branch="${ env.BRANCH_NAME }" | ||
|
||
# - name: Create comment | ||
# uses: peter-evans/create-or-update-comment@v4 | ||
# with: | ||
# issue-number: ${{ github.event.pull_request.number }} | ||
# comment-author: 'github-actions[bot]' | ||
# body: | | ||
# ## ⚡ Removing Cloudflare Pages Preview | ||
# | Name | Status | | ||
# | :--- | :----- | | ||
# | ${{env.BRANCH_NAME}} | ✅ Removed | |