WIP 332 Show Netlify preview URL #71
Workflow file for this run
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
name: GitHub Pages | |
on: | |
pull_request: | |
push: | |
workflow_dispatch: | |
inputs: | |
publish_gh_pages: | |
type: boolean | |
description: 'Publish GH Pages' | |
default: false | |
jobs: | |
build-artifacts: | |
uses: ./.github/workflows/build-artifacts.yml | |
with: | |
# SonarQube requires JDK 17 or higher | |
java-version: '17' | |
generate-site: | |
needs: build-artifacts | |
runs-on: ubuntu-latest | |
concurrency: | |
group: "${{ github.workflow }}-${{ github.ref }}-${{ inputs.publish_gh_pages }}" | |
env: | |
DTC_HEADLESS: true | |
steps: | |
- name: Install dot (Graphviz) | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y graphviz | |
- name: Cache Gradle packages | |
uses: actions/cache@v4 | |
with: | |
path: ~/.gradle/caches | |
key: "${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}" | |
restore-keys: ${{ runner.os }}-gradle | |
- name: Cache .doctoolchain | |
uses: actions/cache@v4 | |
with: | |
path: ~/.doctoolchain | |
key: "${{ runner.os }}-doctoolchain-${{ hashFiles('**/lockfiles') }}" | |
restore-keys: ${{ runner.os }}-doctoolchain | |
- name: Check out | |
uses: actions/checkout@v4 | |
- name: Setup JDK | |
uses: actions/setup-java@v4 | |
with: | |
distribution: temurin | |
java-version: 17 | |
- name: Download Artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: build-artifacts | |
path: . | |
- name: Validate Gradle Wrapper | |
uses: gradle/actions/wrapper-validation@v4 | |
- name: Generate Site | |
run: ./generate-pages | |
- name: Upload Generated Site | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
name: github-pages | |
path: public | |
retention-days: 7 | |
publish-to-github: | |
runs-on: ubuntu-latest | |
needs: generate-site | |
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment | |
permissions: | |
contents: read | |
pages: write # to deploy to Pages | |
id-token: write # to verify the deployment originates from an appropriate source | |
# Deploy to the github-pages environment | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
if: ${{ github.event.inputs.publish_gh_pages }} | |
steps: | |
- name: Configure Pages | |
uses: actions/configure-pages@v5 | |
- name: Deploy Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 | |
publish-to-netlify: | |
runs-on: ubuntu-latest | |
needs: generate-site | |
environment: netlify | |
if: ${{ !github.event.inputs.publish_gh_pages }} | |
steps: | |
- name: Download GitHub Pages Artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: github-pages | |
path: download | |
- name: Unpack GH Pages | |
run: | | |
mkdir -p public | |
tar -x -C public -v -f download/artifact.tar | |
- name: Cache Netlify CLI | |
uses: actions/cache@v4 | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-netlify-cli-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: ${{ runner.os }}-netlify-cli | |
- name: Deploy to Netlify | |
uses: South-Paw/action-netlify-cli@v2 | |
id: netlify | |
with: | |
args: deploy --dir ./public --message 'draft [${{ github.sha }}]' --json | |
env: | |
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} | |
- name: Output Netlify Preview URL | |
run: | | |
echo "The URL where the logs from the deployment can be found" | |
echo "${{ fromJson(steps.netlify.outputs.NETLIFY_OUTPUT).logs }}" | |
echo "" | |
echo "the URL of the draft site that Netlify provides" | |
echo "${{ fromJson(steps.netlify.outputs.NETLIFY_OUTPUT).deploy_url }}" |