Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add github action to deploy to cloudflare pages #7

Merged
merged 39 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
3cd69c7
ci: deploy to cloudflare pages automatically
hydrobeam Nov 19, 2024
6ddaaaf
cleanup hyphens
hydrobeam Nov 19, 2024
4dc4290
idk
hydrobeam Nov 19, 2024
f51d830
fixed
hydrobeam Nov 19, 2024
fe387ae
try it
hydrobeam Nov 19, 2024
743feba
try to make branch go
hydrobeam Nov 19, 2024
d4ff612
add comment
hydrobeam Nov 19, 2024
c45d72f
clean up properly
hydrobeam Nov 19, 2024
4b21004
work it
hydrobeam Nov 19, 2024
a501b8f
change name
hydrobeam Nov 19, 2024
15b870c
append url
hydrobeam Nov 19, 2024
154d74e
switch to deprecated action
hydrobeam Nov 19, 2024
4e27131
cloudflared
hydrobeam Nov 19, 2024
612bd2d
use proper syntax
hydrobeam Nov 19, 2024
3902df6
ref name
hydrobeam Nov 19, 2024
6384c25
lethimcook
hydrobeam Nov 19, 2024
3a40317
trythis
hydrobeam Nov 19, 2024
45c6964
back to back
hydrobeam Nov 19, 2024
ac0fbf9
mosnter
hydrobeam Nov 19, 2024
1c653a5
indent i guess
hydrobeam Nov 19, 2024
5482430
nuke perms?
hydrobeam Nov 19, 2024
b9db996
nuke
hydrobeam Nov 19, 2024
1e4fd53
try stuff
hydrobeam Nov 19, 2024
e049d6b
idek
hydrobeam Nov 19, 2024
f45de37
try
hydrobeam Nov 19, 2024
9352050
fix
hydrobeam Nov 19, 2024
524f161
yolo
hydrobeam Nov 19, 2024
02b3354
yolo
hydrobeam Nov 19, 2024
9966ed3
fixup
hydrobeam Nov 19, 2024
1688a15
cscs
hydrobeam Nov 19, 2024
ff478da
yolo
hydrobeam Nov 19, 2024
54f4eb4
yip
hydrobeam Nov 19, 2024
b671d49
idfk
hydrobeam Nov 19, 2024
a73a7b4
try
hydrobeam Nov 19, 2024
2e08b5a
final attempt
hydrobeam Nov 19, 2024
001a11e
penultimate attempt
hydrobeam Nov 19, 2024
51cf47d
ehh
hydrobeam Nov 19, 2024
c4e13d8
cleanup emojis
hydrobeam Nov 19, 2024
921595a
bold not italic
hydrobeam Nov 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Deploy to Cloudflare Pages

on:
pull_request:
push:
branches:
- "main"

jobs:
deploy:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch

- name: Get latest commit hash of the PR branch
run: |
# Get the latest commit hash of the source branch of the PR
PR_BRANCH="${{ github.head_ref }}"
echo "Pull request branch: $PR_BRANCH"

# Fetch the commit hash for the PR branch
git fetch origin $PR_BRANCH

LATEST_COMMIT=$(git log -n 1 --oneline $PR_BRANCH | cut -d ' ' -f 1)

echo "Latest commit hash: $LATEST_COMMIT"
echo "LATEST_COMMIT=${LATEST_COMMIT}" >> $GITHUB_ENV

- name: Get Head Commit Message
shell: bash
id: get_head_commit_message
run: echo "commit=$(git show -s --format=%s)" >> "$GITHUB_OUTPUT"

# stolen from: https://github.com/cloudflare/pages-action/issues/16#issuecomment-1398478711
- name: Comment deploy start
if: github.event_name != 'push'
uses: mshick/add-pr-comment@v2
with:
message-id: cloudflare-deploy
message: |
### <span aria-hidden="true">🚧</span> Deploy Preview building...

| Name | Link |
|---------------------------------|------------------------|
| **Latest commit** | ${{ env.LATEST_COMMIT }} |
| **Latest deploy log** | ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
---

- name: Install rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.81.0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20.2"

- name: Install wasm-pack
run: |
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

- name: Install npm dependencies
working-directory: crates/org-wasm
run: npm install

- name: Generate wasm binaries
working-directory: crates/org-wasm
run: wasm-pack build --release --target bundler

- name: Deploy npm
working-directory: crates/org-wasm
run: npm run deploy

- name: Publish to Cloudflare
id: deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy crates/org-wasm/dist --project-name=org-rust --branch ${{ steps.extract_branch.outputs.branch }} --commit-hash ${{ env.LATEST_COMMIT }} --commit-message "${{ steps.get_head_commit_message.outputs.commit }}"

- name: Comment deploy url
uses: mshick/add-pr-comment@v2
with:
message-id: cloudflare-deploy
message: |
### <span aria-hidden="true">✅</span> Deploy Preview ready!

| Name | Link |
|---------------------------------|------------------------|
| **Latest commit** | ${{ env.LATEST_COMMIT }} |
| **Latest deploy log** | ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| **Deploy Preview Url** | [${{ steps.deploy.outputs.pages-deployment-alias-url }}](${{ steps.deploy.outputs.pages-deployment-alias-url }}) |
---
4 changes: 1 addition & 3 deletions crates/org-wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@ Then for the site itself (output will be found at `/dist`):
npm run deploy
```

or alternatively:
or alternatively, for dev builds:

```
npm run demo
```

for dev builds.

`/dist` can then be served as is.

### Other
Expand Down