Merge pull request #436 from gethinode/develop

Refactor workflows
This commit is contained in:
Mark Dumay
2023-08-19 06:56:54 +02:00
committed by GitHub
5 changed files with 84 additions and 62 deletions

View File

@@ -1,5 +1,6 @@
name: build
name: Lint & build
on:
workflow_dispatch:
push:
tags:
- v*
@@ -7,24 +8,71 @@ 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:
runs-on: ${{ env.LINT_OS }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.LINT_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
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: ${{ env.CACHE_PATH }}
key: ${{ runner.os }}-${{ env.CACHE_KEY }}
restore-keys: |
${{ runner.os }}-${{ env.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

View File

@@ -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

View File

@@ -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: ${{ env.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: ${{ env.NODE_VERSION }}
registry-url: ${{ env.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 }}

2
config/ci/hugo.toml Normal file
View File

@@ -0,0 +1,2 @@
cachedir = '/tmp/hugo_cache_runner/'
resourcedir = '/tmp/hugo_cache_runner/resources/'

View File

@@ -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",