101 lines
3.2 KiB
YAML
101 lines
3.2 KiB
YAML
name: Deploy Upstream Preview
|
|
|
|
on:
|
|
repository_dispatch:
|
|
types: [trigger-upstream-preview]
|
|
|
|
env:
|
|
USE_MATERIAL_KOLOR_SUBMODULE: true
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
name: Build and Deploy
|
|
if: github.event.pull_request.head.repo.fork == false
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
submodules: "recursive"
|
|
|
|
- name: Update submodule
|
|
run: |
|
|
git submodule update --init --recursive
|
|
cd library
|
|
git fetch origin ${{ github.event.client_payload.commit_hash }}
|
|
git checkout ${{ github.event.client_payload.commit_hash }}
|
|
|
|
- name: Setup Java
|
|
uses: actions/setup-java@v4
|
|
with:
|
|
java-version: 17
|
|
distribution: adopt
|
|
|
|
- name: Setup Gradle
|
|
uses: gradle/actions/setup-gradle@v4
|
|
|
|
- name: Gradle Wrapper Validation
|
|
uses: gradle/actions/wrapper-validation@v4
|
|
|
|
- name: Build web app
|
|
run: ./gradlew wasmJsBrowserDistribution
|
|
|
|
- name: Set Channel ID
|
|
run: |
|
|
if [ -n "${{ github.event.client_payload.pr_number }}" ]; then
|
|
echo "CHANNEL_ID=upstream-pr-${{ github.event.client_payload.pr_number }}" >> $GITHUB_ENV
|
|
else
|
|
echo "CHANNEL_ID=upstream-${{ github.event.client_payload.commit_hash }}" >> $GITHUB_ENV
|
|
fi
|
|
|
|
- name: Deploy to Firebase
|
|
uses: FirebaseExtended/action-hosting-deploy@v0
|
|
with:
|
|
repoToken: ${{ secrets.GITHUB_TOKEN }}
|
|
firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_MATERIALKOLOR }}
|
|
projectId: materialkolor
|
|
channelId: ${{ env.CHANNEL_ID }}
|
|
id: firebase-deploy
|
|
|
|
- name: Comment on PR
|
|
if: github.event.client_payload.pr_number
|
|
uses: actions/github-script@v7
|
|
with:
|
|
github-token: ${{ secrets.MATERIALKOLOR_PR_COMMENT_TOKEN }}
|
|
script: |
|
|
const prNumber = ${{ github.event.client_payload.pr_number }};
|
|
const previewUrl = '${{ steps.firebase-deploy.outputs.details_url }}';
|
|
const commitHash = '${{ github.event.client_payload.commit_hash }}';
|
|
|
|
const commentBody = `Visit the preview URL for this PR (updated for commit ${commitHash.substring(0, 7)}):
|
|
|
|
[${previewUrl}](${previewUrl})
|
|
|
|
<sub>(I'm a bot 🤖)</sub>`;
|
|
|
|
const { data: comments } = await github.rest.issues.listComments({
|
|
owner: 'jordond',
|
|
repo: 'MaterialKolor',
|
|
issue_number: prNumber
|
|
});
|
|
|
|
const botComment = comments.find(comment =>
|
|
comment.body.includes('(I\'m a bot 🤖)')
|
|
);
|
|
|
|
if (botComment) {
|
|
await github.rest.issues.updateComment({
|
|
owner: 'jordond',
|
|
repo: 'MaterialKolor',
|
|
comment_id: botComment.id,
|
|
body: commentBody
|
|
});
|
|
} else {
|
|
await github.rest.issues.createComment({
|
|
owner: 'jordond',
|
|
repo: 'MaterialKolor',
|
|
issue_number: prNumber,
|
|
body: commentBody
|
|
});
|
|
}
|