From 82ef3104285de57f1e6f6945b188206a0a58fccb Mon Sep 17 00:00:00 2001 From: Gerd Aschemann Date: Thu, 15 Aug 2024 07:55:25 +0200 Subject: [PATCH] WIP 332 Separate Site generation and publication ... --- .github/workflows/generate-site.yml | 75 ++++++++ .github/workflows/gh-pages.yml | 162 ------------------ .../workflows/publish-site-to-gh-pages.yml | 22 +++ .github/workflows/publish-to-netlify.yml | 49 ++++++ 4 files changed, 146 insertions(+), 162 deletions(-) create mode 100644 .github/workflows/generate-site.yml delete mode 100644 .github/workflows/gh-pages.yml create mode 100644 .github/workflows/publish-site-to-gh-pages.yml create mode 100644 .github/workflows/publish-to-netlify.yml diff --git a/.github/workflows/generate-site.yml b/.github/workflows/generate-site.yml new file mode 100644 index 00000000..a53d3130 --- /dev/null +++ b/.github/workflows/generate-site.yml @@ -0,0 +1,75 @@ +name: Generate Site + +on: + pull_request: + push: + workflow_dispatch: + +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: 'Publish Test Results' + uses: EnricoMi/publish-unit-test-result-action/linux@v2 + if: always() + with: + files: | + **/build/test-results/**/*.xml + + - name: Upload Generated Site + uses: actions/upload-pages-artifact@v3 + with: + name: github-pages + path: public + retention-days: 7 diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml deleted file mode 100644 index 8dec74d8..00000000 --- a/.github/workflows/gh-pages.yml +++ /dev/null @@ -1,162 +0,0 @@ -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: 'Publish Test Results' - uses: EnricoMi/publish-unit-test-result-action/linux@v2 - if: always() - with: - files: | - **/build/test-results/**/*.xml - - - 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: Get Netlify Preview URL - id: netlify-status - run: | - echo "NETLIFY_DEPLOY_URL=${{ fromJson(steps.netlify.outputs.NETLIFY_OUTPUT).deploy_url }}" >> $GITHUB_ENV - - 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 }}/" - - - name: Set Job Summary - uses: actions/github-script@v7 - with: - script: | - const deployUrl = process.env.NETLIFY_DEPLOY_URL; - github.rest.checks.update({ - owner: context.repo.owner, - repo: context.repo.repo, - check_run_id: context.runId, - output: { - title: 'Netlify Deployment', - summary: `Netlify Preview URL: ${deployUrl}` - } - }); \ No newline at end of file diff --git a/.github/workflows/publish-site-to-gh-pages.yml b/.github/workflows/publish-site-to-gh-pages.yml new file mode 100644 index 00000000..5abcf0b2 --- /dev/null +++ b/.github/workflows/publish-site-to-gh-pages.yml @@ -0,0 +1,22 @@ +name: Publish GitHub Pages + +on: + workflow_dispatch: + +jobs: + publish-to-github: + runs-on: ubuntu-latest + permissions: + contents: read + pages: write + id-token: write + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - name: Configure Pages + uses: actions/configure-pages@v5 + + - name: Deploy Pages + id: deployment + uses: actions/deploy-pages@v4 \ No newline at end of file diff --git a/.github/workflows/publish-to-netlify.yml b/.github/workflows/publish-to-netlify.yml new file mode 100644 index 00000000..23ae6fa5 --- /dev/null +++ b/.github/workflows/publish-to-netlify.yml @@ -0,0 +1,49 @@ +name: Publish to Netlify + +on: + workflow_dispatch: + +jobs: + publish-to-netlify: + runs-on: ubuntu-latest + environment: + name: netlify + url: ${{ steps.netlify-status.outputs.NETLIFY_DEPLOY_URL }} + steps: + - name: Download Generated Site Artifact + uses: actions/download-artifact@v4 + with: + name: github-pages + path: download + + - name: Unpack Generated Site + 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: Get Netlify Preview URL + id: netlify-status + run: | + echo "NETLIFY_DEPLOY_URL=${{ fromJson(steps.netlify.outputs.NETLIFY_OUTPUT).deploy_url }}" >> $GITHUB_OUTPUT + + 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 }}/" \ No newline at end of file