From d6a5d605a2173f0d4c3e4e94b71b564b9eb0393a Mon Sep 17 00:00:00 2001 From: Mark Cottman-Fields Date: Mon, 1 Jul 2024 15:14:52 +1000 Subject: [PATCH] add schedule action to update website --- .github/workflows/pages-scheduled.yml | 77 ++++++++++++++++++++++++ .github/workflows/pages.yml | 44 ++++++-------- .support/generate_latest_release_info.sh | 10 ++- 3 files changed, 101 insertions(+), 30 deletions(-) create mode 100644 .github/workflows/pages-scheduled.yml diff --git a/.github/workflows/pages-scheduled.yml b/.github/workflows/pages-scheduled.yml new file mode 100644 index 0000000..ad2dbbe --- /dev/null +++ b/.github/workflows/pages-scheduled.yml @@ -0,0 +1,77 @@ +name: Deploy Website scheduled + +on: + schedule: + # At 10:00 on Monday. + - cron: '0 10 * * 1' + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + + # Build and upload the GitHub Pages artifact. + build: + runs-on: ubuntu-latest + needs: + - recent-redbox-release + - static-files + steps: + - name: Checkout + uses: actions/checkout@v4.1.7 + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.3' + # runs 'bundle install' and caches installed gems automatically + bundler-cache: true + # Increment this number if you need to re-download cached gems + cache-version: 0 + + - name: Setup Pages + uses: actions/configure-pages@v5.0.0 + + # Generate an include file showing details for + # the latest ReDBox release. + - name: Create latest ReDBox release details if not cached + run: .support/generate_latest_release_info.sh + + # Update the static website files + - uses: actions/setup-node@v4.0.2 + with: + node-version: 20 + cache: 'npm' + + - name: Update the static files + run: .support/update_static_files.sh + + - name: Build with Jekyll + # Outputs to the './_site' directory by default + run: bundle exec jekyll build + env: + JEKYLL_ENV: production + + - name: Upload artifact + uses: actions/upload-pages-artifact@v3.0.1 + + # Deployment job + deploy: + runs-on: ubuntu-latest + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4.0.5 \ No newline at end of file diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index 75d4b9a..d3d5e89 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -24,35 +24,39 @@ concurrency: cancel-in-progress: false jobs: - # Generate an include file showing details for - # the latest ReDBox release. - recent-redbox-release: + + # Build and upload the GitHub Pages artifact. + build: runs-on: ubuntu-latest + needs: + - recent-redbox-release + - static-files steps: - name: Checkout uses: actions/checkout@v4.1.7 - - name: Cache ReDBox latest release files - id: cache-redbox-latest-release-file + # Generate an include file showing details for + # the latest ReDBox release. + - name: Cache modified files + id: cache-modified-files uses: actions/cache@v4.0.2 env: - cache-name: cache-redbox-latest-release-file + cache-name: cache-modified-files with: path: | .support/rblatest.json _includes/latest_release.html - key: cache-redbox-latest-release-file + static/js/bootstrap.bundle.min.js + static/css/bootstrap.min.css + static/css/bootstrap-icons.min.css + static/css/fonts/bootstrap-icons.woff + static/css/fonts/bootstrap-icons.woff2 + key: cache-modified-files - if: ${{ steps.cache-redbox-latest-release-file.outputs.cache-hit != 'true' }} name: Create latest ReDBox release details if not cached run: .support/generate_latest_release_info.sh - static-files: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4.1.7 - - uses: actions/setup-node@v4.0.2 with: node-version: 20 @@ -61,16 +65,6 @@ jobs: - name: Update the static files run: .support/update_static_files.sh - # Build and upload the GitHub Pages artifact. - build: - runs-on: ubuntu-latest - needs: - - recent-redbox-release - - static-files - steps: - - name: Checkout - uses: actions/checkout@v4.1.7 - - name: Setup Ruby uses: ruby/setup-ruby@v1 with: @@ -85,11 +79,12 @@ jobs: - name: Build with Jekyll # Outputs to the './_site' directory by default - run: bundle exec jekyll build --baseurl "${{ steps.pages.outputs.base_path }}" + run: bundle exec jekyll build env: JEKYLL_ENV: production - name: Upload artifact + if: ${{ ! startsWith(github.ref, 'refs/heads/dependabot') }} uses: actions/upload-pages-artifact@v3.0.1 # Deployment job @@ -99,6 +94,7 @@ jobs: name: github-pages url: ${{ steps.deployment.outputs.page_url }} needs: build + if: ${{ ! startsWith(github.ref, 'refs/heads/dependabot') }} steps: - name: Deploy to GitHub Pages id: deployment diff --git a/.support/generate_latest_release_info.sh b/.support/generate_latest_release_info.sh index 7101e2f..209bf74 100755 --- a/.support/generate_latest_release_info.sh +++ b/.support/generate_latest_release_info.sh @@ -5,12 +5,10 @@ set -euo pipefail DATA_FILE=.support/rblatest.json HTML_FILE=_includes/latest_release.html -if [ ! -f "${DATA_FILE}" ]; then - curl --silent -L -o "${DATA_FILE}" \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - https://api.github.com/repos/redbox-mint/redbox-portal/releases/latest -fi +curl --silent -L -o "${DATA_FILE}" \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/redbox-mint/redbox-portal/releases/latest VERSION=$(jq -r '.tag_name' "${DATA_FILE}") URL=$(jq -r '.html_url' "${DATA_FILE}")