From ff82ded064ab1ff73ce42dd6b9af750201a73c66 Mon Sep 17 00:00:00 2001 From: mark Date: Sat, 19 Aug 2023 05:38:56 +0200 Subject: [PATCH 1/7] Refactor npm publish workflow --- .github/workflows/npm-publish.yml | 49 ++++++++++++++++--------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 4cc02155..e5ed91df 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -1,35 +1,36 @@ -# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created -# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages - -name: Node.js Package +# This workflow will run tests using node and then publish a package to npmjs.org when a release is created +# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages +name: Publish package to npmjs on: workflow_dispatch: - branches: [ main ] release: - types: [created] + types: [published] + +env: + OS: 'ubuntu-latest' + NODE_VERSION: '16.x' + REGISTRY_URL: 'https://registry.npmjs.org/' jobs: build: - runs-on: ubuntu-latest + runs-on: $OS steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 16 - - run: npm ci - - run: npm test + - name: Checkout repository + uses: actions/checkout@v3 - publish-npm: - needs: build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - name: Setup .npmrc file to publish to npm + uses: actions/setup-node@v3 with: - node-version: 16 - registry-url: https://registry.npmjs.org/ - - run: npm ci - - run: npm publish + node-version: $NODE_VERSION + registry-url: $REGISTRY_URL + cache: 'npm' + cache-dependency-path: '**/package-lock.json' + + - name: Perform clean install of npm + run: npm ci + + - name: Publish package to npm + run: npm publish env: - NODE_AUTH_TOKEN: ${{secrets.npm_token}} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} From d82ed7998965e38c7bb5d82a84434953a9b92b64 Mon Sep 17 00:00:00 2001 From: mark Date: Sat, 19 Aug 2023 06:12:45 +0200 Subject: [PATCH 2/7] Refactor lint and build workflows --- .github/workflows/build.yml | 65 +++++++++++++++++++++++++++++++++---- .github/workflows/lint.yml | 31 ------------------ 2 files changed, 58 insertions(+), 38 deletions(-) delete mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 89ef48f0..ae8df026 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,5 +1,6 @@ -name: build +name: Lint & build on: + workflow_dispatch: push: tags: - v* @@ -8,23 +9,73 @@ on: branches: [ main ] jobs: + lint: + env: + OS: 'ubuntu-latest' + NODE_VERSION: '20.x' + + runs-on: $OS + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: $NODE_VERSION + cache: 'npm' + cache-dependency-path: '**/package-lock.json' + + - name: Perform clean install of npm + run: npm ci + + - name: Lint the source files + run: npm run lint + build: + needs: lint + + env: + CACHE_KEY: 'hugo-hinode' + CACHE_PATH: '/tmp/hugo_cache_runner' + NODE_VERSION: '20.x' + strategy: matrix: os: [macos-latest, windows-latest, ubuntu-latest] - node-version: [16.x, 18.x, 20.x] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + node-version: [16.x, 18.x, 20.x] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 - - name: Use Node.js ${{ matrix.node-version }} + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} cache: 'npm' cache-dependency-path: '**/package-lock.json' - - run: npm ci - - run: npm run build - - run: npm run build:example + + - name: Perform clean install of npm + run: npm ci + + # Cache Hugo cachedir and resourcedir (configured in config/ci/hugo.toml) for each OS + # No additional cache invalidation is needed, Hugo uses checksums itself + - name: Use Hugo cache + uses: actions/cache@v3 + with: + path: $CACHE_PATH + key: ${{ runner.os }}-$CACHE_KEY + restore-keys: | + ${{ runner.os }}-$CACHE_KEY + + - name: Build main site + run: npm run build:cache + + # The example site is to be published to demo.gethinode.com + - name: Build example site + run: npm run build:example:ci diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index a7a783a1..00000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: lint -on: - push: - tags: - - v* - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - build: - - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [16.x, 18.x, 20.x] - # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ - - steps: - - uses: actions/checkout@v3 - - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - cache: 'npm' - cache-dependency-path: '**/package-lock.json' - - - run: npm ci --ignore-scripts - - run: npm run lint From 7a9cb1b2ca1593c78a8a331c41138be5a6b359be Mon Sep 17 00:00:00 2001 From: mark Date: Sat, 19 Aug 2023 06:13:10 +0200 Subject: [PATCH 3/7] Add ci build cache configuration --- config/ci/hugo.toml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 config/ci/hugo.toml diff --git a/config/ci/hugo.toml b/config/ci/hugo.toml new file mode 100644 index 00000000..de1e4da2 --- /dev/null +++ b/config/ci/hugo.toml @@ -0,0 +1,2 @@ +cachedir = '/tmp/hugo_cache_runner/' +resourcedir = '/tmp/hugo_cache_runner/resources/' From 77fad02da71ebb0f3fa113bc976fb4e89a33dbdd Mon Sep 17 00:00:00 2001 From: mark Date: Sat, 19 Aug 2023 06:14:00 +0200 Subject: [PATCH 4/7] Add cache to build commands --- package.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package.json b/package.json index 82d9d69e..354723cf 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,9 @@ "start:prod": "hugo server --bind=0.0.0.0 --disableFastRender --printI18nWarnings -e production", "prebuild": "npm run clean:public && npm run -s mod:install", "build": "hugo --gc --minify", + "build:cache": "npm run -s prebuild && hugo --gc --minify -e ci", "build:example": "npm run -s prebuild && hugo --gc --minify -s exampleSite", + "build:example:ci": "npm run -s prebuild && hugo --gc --minify -s exampleSite -e ci", "build:debug": "hugo -e debug --debug", "build:preview": "npm run build -D -F", "clean:public": "rimraf public", From 0caf473897c89c84fa6433bdeda8ad8abe1f59e5 Mon Sep 17 00:00:00 2001 From: mark Date: Sat, 19 Aug 2023 06:42:47 +0200 Subject: [PATCH 5/7] Consolidate env vars --- .github/workflows/build.yml | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ae8df026..42755109 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,13 +8,15 @@ on: pull_request: branches: [ main ] +env: + LINT_OS: 'ubuntu-latest' + LINT_NODE_VERSION: '20.x' + CACHE_KEY: 'hugo-hinode' + CACHE_PATH: '/tmp/hugo_cache_runner' + jobs: lint: - env: - OS: 'ubuntu-latest' - NODE_VERSION: '20.x' - - runs-on: $OS + runs-on: $LINT_OS steps: - name: Checkout repository @@ -23,7 +25,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v3 with: - node-version: $NODE_VERSION + node-version: $LINT_NODE_VERSION cache: 'npm' cache-dependency-path: '**/package-lock.json' @@ -36,11 +38,6 @@ jobs: build: needs: lint - env: - CACHE_KEY: 'hugo-hinode' - CACHE_PATH: '/tmp/hugo_cache_runner' - NODE_VERSION: '20.x' - strategy: matrix: os: [macos-latest, windows-latest, ubuntu-latest] From 23279d97103e5e83f7562463c9c4ca0e696f96cb Mon Sep 17 00:00:00 2001 From: mark Date: Sat, 19 Aug 2023 06:51:27 +0200 Subject: [PATCH 6/7] Adjust env var reference --- .github/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 42755109..a65d4f73 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,7 @@ env: jobs: lint: - runs-on: $LINT_OS + runs-on: ${{ env.LINT_OS }} steps: - name: Checkout repository @@ -25,7 +25,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v3 with: - node-version: $LINT_NODE_VERSION + node-version: ${{ env.LINT_NODE_VERSION }} cache: 'npm' cache-dependency-path: '**/package-lock.json' @@ -66,9 +66,9 @@ jobs: uses: actions/cache@v3 with: path: $CACHE_PATH - key: ${{ runner.os }}-$CACHE_KEY + key: ${{ runner.os }}-${{ env.$CACHE_KEY }} restore-keys: | - ${{ runner.os }}-$CACHE_KEY + ${{ runner.os }}-${{ env.$CACHE_KEY }} - name: Build main site run: npm run build:cache From 828e531b52b0f91781b22bbd1c6779868bb99279 Mon Sep 17 00:00:00 2001 From: mark Date: Sat, 19 Aug 2023 06:53:53 +0200 Subject: [PATCH 7/7] Adjust env var reference --- .github/workflows/build.yml | 6 +++--- .github/workflows/npm-publish.yml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a65d4f73..b2114164 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -65,10 +65,10 @@ jobs: - name: Use Hugo cache uses: actions/cache@v3 with: - path: $CACHE_PATH - key: ${{ runner.os }}-${{ env.$CACHE_KEY }} + path: ${{ env.CACHE_PATH }} + key: ${{ runner.os }}-${{ env.CACHE_KEY }} restore-keys: | - ${{ runner.os }}-${{ env.$CACHE_KEY }} + ${{ runner.os }}-${{ env.CACHE_KEY }} - name: Build main site run: npm run build:cache diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index e5ed91df..87c50a6e 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -14,7 +14,7 @@ env: jobs: build: - runs-on: $OS + runs-on: ${{ env.OS }} steps: - name: Checkout repository uses: actions/checkout@v3 @@ -22,8 +22,8 @@ jobs: - name: Setup .npmrc file to publish to npm uses: actions/setup-node@v3 with: - node-version: $NODE_VERSION - registry-url: $REGISTRY_URL + node-version: ${{ env.NODE_VERSION }} + registry-url: ${{ env.REGISTRY_URL }} cache: 'npm' cache-dependency-path: '**/package-lock.json'