Skip to content

chore: update build from https://github.com/dimaslanjaka/static-blog-… #147

chore: update build from https://github.com/dimaslanjaka/static-blog-…

chore: update build from https://github.com/dimaslanjaka/static-blog-… #147

Workflow file for this run

name: Build Utility
# reference: https://github.com/dimaslanjaka/nodejs-package-types/blob/main/.github/workflows/build-release.yml
on:
push:
branches: ['sbg-utility']
paths:
- '**/src/**'
- '**/sbg-utility.yml'
- '**/package-lock.json'
- '**/package.json'
- '**/yarn.lock'
- '**/gulpfile*'
pull_request:
types:
- closed
workflow_dispatch:
workflow_call:
secrets:
ACCESS_TOKEN:
required: true
concurrency:
group: build-sbg-utility
cancel-in-progress: true
jobs:
build:
env:
NODE_OPTIONS: '--max_old_space_size=8192'
YARN_ENABLE_IMMUTABLE_INSTALLS: false
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
node-version: 20.x
YARN_CHECKSUM_BEHAVIOR: update
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout Repository (sbg-utility)
uses: actions/checkout@v4
with:
repository: dimaslanjaka/static-blog-generator
ref: sbg-utility
token: ${{ secrets.ACCESS_TOKEN }}
submodules: true
- name: ⚙️ Initialize Environment Variables
id: set-env
shell: bash
run: |
echo "${HOME}/.local/bin" >> $GITHUB_PATH
echo "${GITHUB_WORKSPACE}/bin" >> $GITHUB_PATH
echo "${GITHUB_WORKSPACE}/node_modules/.bin" >> $GITHUB_PATH
echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV
echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_OUTPUT
echo "GITHUB_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
echo "GITHUB_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
echo "GITHUB_COMMIT_URL=https://github.com/${{github.repository}}/commit/$(echo $GITHUB_SHA)" >> $GITHUB_ENV
echo "GITHUB_COMMIT_URL=https://github.com/${{github.repository}}/commit/$(echo $GITHUB_SHA)" >> $GITHUB_OUTPUT
echo "GITHUB_RUNNER_URL=https://github.com/${{github.repository}}/commit/${{github.sha}}/checks/${{github.run_id}}" >> $GITHUB_ENV
echo "GITHUB_RUNNER_URL=https://github.com/${{github.repository}}/commit/${{github.sha}}/checks/${{github.run_id}}" >> $GITHUB_OUTPUT
echo "CACHE_NPM=$(npm config get cache)" >> $GITHUB_ENV
echo "CACHE_NPM=$(npm config get cache)" >> $GITHUB_OUTPUT
YARN_CURRENT=$(yarn -v)
YARN_BERRY=3.2.1
if [[ "ok" == "$(echo | awk "(${YARN_CURRENT} > ${YARN_BERRY}) { print \"ok\"; }")" ]]; then
echo "CACHE_YARN=$(yarn config get cacheFolder)" >> $GITHUB_ENV
echo "CACHE_YARN=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
else
echo "CACHE_YARN=$(yarn cache dir)" >> $GITHUB_ENV
echo "CACHE_YARN=$(yarn cache dir)" >> $GITHUB_OUTPUT
fi
echo "architecture=$(getconf LONG_BIT)" >> $GITHUB_ENV
if [ -f "package-lock.json" ]; then
echo "PACKAGE-MANAGER=npm" >> $GITHUB_OUTPUT
echo "PACKAGE-MANAGER=npm" >> $GITHUB_ENV
else
echo "PACKAGE-MANAGER=yarn" >> $GITHUB_OUTPUT
echo "PACKAGE-MANAGER=yarn" >> $GITHUB_ENV
fi
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) machine=linux;;
Darwin*) machine=mac;;
CYGWIN*) machine=cygwin;;
MINGW*) machine=mingw;;
*) machine="unknown:${unameOut}"
esac
echo "machine=$machine" >> $GITHUB_OUTPUT
echo "machine=$machine" >> $GITHUB_ENV
- name: 🧹 Set Git Line Endings (EOL)
continue-on-error: true
run: |
git config core.eol lf
git config core.autocrlf input
git checkout-index --force --all
- name: 📦 Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.node-version }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: 🚀 Enable Corepack for Yarn
run: corepack enable
- name: 📦 Restore Project Cache
uses: pat-s/[email protected]
id: cache
with:
path: |
**/.yarn
**/release*
**/yarn.lock
**/node_modules
**/tmp
**/dist
key: ${{ runner.os }}-${{ env.node-version }}
restore-keys: |
${{ runner.os }}-${{ env.node-version }}
${{ runner.os }}-
- name: 🌍 Install Global Dev Dependencies
run: npm i -g typescript ts-node gulp-cli
- name: 🔧 Set Yarn configuration
run: |
YARN_CURRENT=$(yarn -v)
YARN_BERRY=3.2.1
if [[ "ok" == "$(echo | awk "(${YARN_CURRENT} > ${YARN_BERRY}) { print \"ok\"; }")" ]]; then
yarn config set enableImmutableInstalls false
yarn config set enableInlineBuilds true
yarn config set enableScripts true
yarn config set nodeLinker node-modules
yarn set version 4.9.2
yarn config set cacheFolder "${GITHUB_WORKSPACE}/packages/sbg-utility/.yarn/caches"
fi
working-directory: packages/sbg-utility
- name: 📥 Install Dependencies (sbg-utility)
run: |
touch yarn.lock
yarn install
working-directory: packages/sbg-utility
- name: 🧽 Clean Previous Builds
working-directory: packages/sbg-utility
run: yarn run clean
- name: 🏗️ Build Project
working-directory: packages/sbg-utility
run: yarn run build
- name: 📦 Package Build Artifacts
working-directory: packages/sbg-utility
run: |
npm run pack -- --commit
npm run pack
- name: 🛠️ Configure Git user
run: |
git config --global user.email "[email protected]"
git config --global user.name "dimaslanjaka"
- name: ➕ Git Add Changes
working-directory: packages/sbg-utility
run: |
git add -A
# --- original commit step backup ---
# - name: 📤 Commit and Push Changes
# working-directory: packages/sbg-utility
# run: |
# if [ $(git status --porcelain | wc -l) -gt "0" ]; then
# git commit -m "chore: update build from ${{ env.GITHUB_COMMIT_URL }}" -m "commit hash: ${{ env.GITHUB_SHA_SHORT }}" -m "commit url: ${{ env.GITHUB_COMMIT_URL }}" -m "runner: ${{ env.GITHUB_RUNNER_URL }}"
# git push
# fi
- name: 📤 Commit and Push Changes (only sbg-utility)
working-directory: packages/sbg-utility
run: |
if [ $(git status --porcelain -- . | wc -l) -gt "0" ]; then
git commit -m "chore: update build from ${{ env.GITHUB_COMMIT_URL }}" -m "commit hash: ${{ env.GITHUB_SHA_SHORT }}" -m "commit url: ${{ env.GITHUB_COMMIT_URL }}" -m "runner: ${{ env.GITHUB_RUNNER_URL }}"
git push
fi