Skip to content

Commit

Permalink
chore: add firebase hosting preview URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
jbms committed Feb 22, 2024
1 parent 0f131d3 commit 76199e6
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 2 deletions.
15 changes: 15 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"projects": {
"default": "neuroglancer-demo"
},
"targets": {
"neuroglancer-demo": {
"hosting": {
"app": [
"neuroglancer"
]
}
}
},
"etags": {}
}
2 changes: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ jobs:
matrix:
python-version:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
node-version:
- "20.x"
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/build_preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build preview

on:
pull_request:

jobs:
upload:
strategy:
matrix:
node-version:
- "20.x"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: |
build_info="{'tag':'$(git describe --always --tags)', 'url':'https://github.com/google/neuroglancer/commit/$(git rev-parse HEAD)', 'timestamp':'$(date)'}"
npm run build -- --define NEUROGLANCER_BUILD_INFO="${build_info}"
- name: Upload client as artifact
uses: actions/upload-artifact@v4
with:
name: client
path: |
dist/min/*
65 changes: 65 additions & 0 deletions .github/workflows/deploy_preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Deploy preview

on:
workflow_run:
worflows: ["Build preview"]
types: [completed]

jobs:
deploy:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: client
path: dist/min
github-token: "${{ secrets.GITHUB_TOKEN }}"
run-id: "${{ context.payload.workflow_run.id }}"
- name: Get PR ID
# https://github.com/orgs/community/discussions/25220#discussioncomment-7532132
id: pr-id
run: |
PR_ID=$(gh run view -R ${{ github.repository }} ${{ github.event.workflow_run.id }} | grep -oP '#[0-9]+ . ${{ github.event.workflow_run.id }}' | grep -oP '#[0-9]+' | cut -c 2-)
echo "pr-id=${PR_ID}" >> $GITHUB_OUTPUT
- uses: FirebaseExtended/action-hosting-deploy@v0
id: deploy
with:
repoToken: "${{ secrets.GITHUB_TOKEN }}"
firebaseServiceAccount: "${{ secrets.FIREBASE_HOSTING_SERVICE_ACCOUNT_KEY }}"
expires: 30d
channel: "pr${{ steps.pr-id.outputs.pr-id }}"
projectId: neuroglancer-demo
- name: "Comment on PR"
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issueNumber = ${{ steps.pr-id.outputs.pr-id }};
const MESSAGE_START = "\n\n<!-- Firebase hosting preview start -->\n";
const MESSAGE_END = "\n<!-- Firebase hosting preview end -->\n";
const message = `----
🔥 Preview 🔥: ${{ steps.deploy.outputs.details_url }}
Updated at ${Date.now()} for commit ${{ github.event.workflow_run.head_commit.id }}
Expires: ${{ steps.deploy.outputs.expire_time }}
`;
const { data: pull } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: issueNumber,
});
let body = "";
if (pull.body && pull.body.includes(MESSAGE_SEPARATOR_START)) {
body = pull.body.slice(0, pull.body.indexOf(MESSAGE_SEPARATOR_START));
body = body + MESSAGE_SEPARATOR_START + message + MESSAGE_SEPARATOR_END;
body = body + pull.body.slice(pull.body.indexOf(MESSAGE_SEPARATOR_END) + MESSAGE_SEPARATOR_END.length);
} else {
body = MESSAGE_SEPARATOR_START + message + MESSAGE_SEPARATOR_END;
}
github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
body: body,
});
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ tsconfig.tsbuildinfo
/ngauth_server/secrets/
.eslintcache
/lib
/.firebase
6 changes: 6 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"hosting": {
"target": "app",
"public": "dist/min"
}
}

0 comments on commit 76199e6

Please sign in to comment.