|
| 1 | +# GitHub Actions workflow to build and deploy the browser compiler demo to GitHub Pages |
| 2 | + |
| 3 | +name: Deploy Demo to GitHub Pages |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: [main, master] |
| 8 | + paths: |
| 9 | + - 'browser-interpreter/**' |
| 10 | + pull_request: |
| 11 | + branches: [main, master] |
| 12 | + paths: |
| 13 | + - 'browser-interpreter/**' |
| 14 | + workflow_dispatch: # Allow manual trigger from any branch |
| 15 | + inputs: |
| 16 | + deploy: |
| 17 | + description: 'Deploy to GitHub Pages' |
| 18 | + required: false |
| 19 | + default: true |
| 20 | + type: boolean |
| 21 | + |
| 22 | +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages |
| 23 | +permissions: |
| 24 | + contents: read |
| 25 | + pages: write |
| 26 | + id-token: write |
| 27 | + |
| 28 | +# Allow only one concurrent deployment |
| 29 | +concurrency: |
| 30 | + group: "pages" |
| 31 | + cancel-in-progress: true |
| 32 | + |
| 33 | +jobs: |
| 34 | + build: |
| 35 | + runs-on: ubuntu-latest |
| 36 | + |
| 37 | + steps: |
| 38 | + - name: Checkout |
| 39 | + uses: actions/checkout@v4 |
| 40 | + |
| 41 | + - name: Setup Java |
| 42 | + uses: actions/setup-java@v4 |
| 43 | + with: |
| 44 | + distribution: 'temurin' |
| 45 | + java-version: '21' |
| 46 | + cache: 'sbt' |
| 47 | + |
| 48 | + - name: Build Scala.js |
| 49 | + working-directory: browser-interpreter |
| 50 | + run: sbt js/fastLinkJS |
| 51 | + |
| 52 | + - name: Prepare deployment files |
| 53 | + run: | |
| 54 | + mkdir -p _site |
| 55 | +
|
| 56 | + # Find the Scala version from the build output |
| 57 | + SCALA_VERSION=$(ls browser-interpreter/js/target/ | grep scala | head -1) |
| 58 | + echo "Scala version: $SCALA_VERSION" |
| 59 | +
|
| 60 | + # Copy the demo HTML as index.html, updating the JS path if needed |
| 61 | + sed "s|js/target/scala-[0-9.]*|js/target/$SCALA_VERSION|g" \ |
| 62 | + browser-interpreter/demo-compiler.html > _site/index.html |
| 63 | +
|
| 64 | + # Copy the generated JavaScript |
| 65 | + mkdir -p "_site/js/target/$SCALA_VERSION" |
| 66 | + cp -r "browser-interpreter/js/target/$SCALA_VERSION/browser-interpreter-js-fastopt" \ |
| 67 | + "_site/js/target/$SCALA_VERSION/" |
| 68 | +
|
| 69 | + # Add .nojekyll to prevent Jekyll processing |
| 70 | + touch _site/.nojekyll |
| 71 | +
|
| 72 | + # Show what we're deploying |
| 73 | + echo "Deployment contents:" |
| 74 | + find _site -type f | head -20 |
| 75 | +
|
| 76 | + - name: Setup Pages |
| 77 | + uses: actions/configure-pages@v4 |
| 78 | + |
| 79 | + - name: Upload artifact |
| 80 | + uses: actions/upload-pages-artifact@v3 |
| 81 | + with: |
| 82 | + path: '_site' |
| 83 | + |
| 84 | + deploy: |
| 85 | + # Only deploy on push to main/master or manual trigger with deploy=true |
| 86 | + if: | |
| 87 | + github.event_name == 'push' || |
| 88 | + (github.event_name == 'workflow_dispatch' && inputs.deploy) |
| 89 | + environment: |
| 90 | + name: github-pages |
| 91 | + url: ${{ steps.deployment.outputs.page_url }} |
| 92 | + runs-on: ubuntu-latest |
| 93 | + needs: build |
| 94 | + |
| 95 | + steps: |
| 96 | + - name: Deploy to GitHub Pages |
| 97 | + id: deployment |
| 98 | + uses: actions/deploy-pages@v4 |
| 99 | + |
0 commit comments