From b7545de98094bc91f4890347e9452c8390146626 Mon Sep 17 00:00:00 2001 From: rlskoeser Date: Wed, 4 Oct 2023 16:45:53 -0400 Subject: [PATCH] Set hugo and node versions in one place; update gh pages workflow --- .github/workflows/check-i18n.yml | 11 ++--- .github/workflows/gh-pages.yml | 62 ++++++++++++++++++++++------- .github/workflows/lighthouse-ci.yml | 9 +++-- .hugo_version | 1 + package.json | 3 ++ 5 files changed, 63 insertions(+), 23 deletions(-) create mode 100644 .hugo_version diff --git a/.github/workflows/check-i18n.yml b/.github/workflows/check-i18n.yml index af1e9b36..b79c3e97 100644 --- a/.github/workflows/check-i18n.yml +++ b/.github/workflows/check-i18n.yml @@ -3,11 +3,6 @@ name: hugo i18n check on: pull_request: -# versions should be kept in sync with gh-pages and lighthouse-ci workflow -env: - HUGO_VERSION: 0.119.0 # if you update this, change the README badge and lighthouse-ci.yml too! - NODE_VERSION: 18 # if you update this, change the README badge and lighthouse-ci.yml too! - jobs: build-deploy: name: Check Hugo i18n translations @@ -17,12 +12,18 @@ jobs: - name: checkout repository uses: actions/checkout@v3 + - name: Get Hugo version + run: echo "HUGO_VERSION=$(cat .hugo_version)" >> $GITHUB_ENV + - name: setup hugo uses: peaceiris/actions-hugo@v2 with: hugo-version: ${{ env.HUGO_VERSION }} extended: true + - name: Get node version from package.json + run: echo "NODE_VERSION=$(cat package.json | jq -r '.volta.node')" >> $GITHUB_ENV + - name: setup node.js uses: actions/setup-node@v2-beta with: diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index 8bbfe0bb..18ef79ae 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -1,30 +1,49 @@ name: github pages on: + # Runs on pushes targeting the default branch push: - branches: - - main + branches: ["main"] -# versions should be kept in sync with lighthouse-ci workflow -env: - HUGO_VERSION: 0.119.0 # if you update this, change the README badge and lighthouse-ci.yml too! - NODE_VERSION: 18 # if you update this, change the README badge and lighthouse-ci.yml too! + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow one concurrent deployment +concurrency: + group: "pages" + cancel-in-progress: true + +# Default to bash +defaults: + run: + shell: bash jobs: - build-deploy: - name: build site and deploy to github pages + build: runs-on: ubuntu-latest steps: - name: checkout repository uses: actions/checkout@v3 + - name: Get Hugo version + run: echo "HUGO_VERSION=$(cat .hugo_version)" >> $GITHUB_ENV + - name: setup hugo uses: peaceiris/actions-hugo@v2 with: hugo-version: ${{ env.HUGO_VERSION }} extended: true + - name: Get node version from package.json + run: echo "NODE_VERSION=$(cat package.json | jq -r '.volta.node')" >> $GITHUB_ENV + - name: setup node.js uses: actions/setup-node@v3 with: @@ -42,11 +61,24 @@ jobs: - name: install js dependencies run: npm ci - - name: build site - run: hugo --minify + - name: Build with Hugo + env: + # For maximum backward compatibility with Hugo modules + HUGO_ENVIRONMENT: production + HUGO_ENV: production + run: | + hugo \ + --minify \ + --baseURL ${{ steps.pages.outputs.base_url }} - - name: deploy site to github pages - uses: peaceiris/actions-gh-pages@v3 - with: - deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} - publish_dir: ./public + # Deployment job + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v2 diff --git a/.github/workflows/lighthouse-ci.yml b/.github/workflows/lighthouse-ci.yml index dac98f82..911a4065 100644 --- a/.github/workflows/lighthouse-ci.yml +++ b/.github/workflows/lighthouse-ci.yml @@ -2,10 +2,7 @@ name: lighthouse ci on: [push] -# versions should be kept in sync with gh-pages workflow env: - HUGO_VERSION: 0.119.0 # if you update this, change the README badge and gh-pages.yml too! - NODE_VERSION: 18 # if you update this, change the README badge and gh-pages.yml too! LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }} jobs: @@ -17,12 +14,18 @@ jobs: - name: checkout repository uses: actions/checkout@v4 + - name: Get Hugo version + run: echo "HUGO_VERSION=$(cat .hugo_version)" >> $GITHUB_ENV + - name: setup hugo uses: peaceiris/actions-hugo@v2 with: hugo-version: ${{ env.HUGO_VERSION }} extended: true + - name: Get node version from package.json + run: echo "NODE_VERSION=$(cat package.json | jq -r '.volta.node')" >> $GITHUB_ENV + - name: setup node.js uses: actions/setup-node@v3 with: diff --git a/.hugo_version b/.hugo_version new file mode 100644 index 00000000..6b5e6fc2 --- /dev/null +++ b/.hugo_version @@ -0,0 +1 @@ +0.119.0 \ No newline at end of file diff --git a/package.json b/package.json index 9ec1ad18..96963476 100644 --- a/package.json +++ b/package.json @@ -23,5 +23,8 @@ "homepage": "https://startwords.cdh.princeton.edu/", "engines": { "node": ">=18" + }, + "volta": { + "node": "18.18.0" } }