Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

ci(github-action): bump dependabot/fetch-metadata from 2.0.0 to 2.1.0 #2985

ci(github-action): bump dependabot/fetch-metadata from 2.0.0 to 2.1.0

ci(github-action): bump dependabot/fetch-metadata from 2.0.0 to 2.1.0 #2985

Workflow file for this run

---
name: NextJS build and release
# description: lint, test, build and release NextJS
on: push
env:
FORCE_COLOR: true # display terminal colors
# APP_NAME: app_name
# GHCR_IMAGE: ghcr.io/<user>/<repo name>
CONTAINER_REGISTRY: ghcr.io
IMAGE_NAME: clumsy-coder/pihole-dashboard
####################################################################################################
jobs:
# install npm packages and store them as cache.
install:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: latest
- name: Cache node modules
id: cache-primes
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-node-
# skip npm ci if `package.json` didn't change
# https://github.com/actions/cache#outputs
# https://github.com/actions/cache#restoring-and-saving-cache-using-a-single-action
- name: Install npm dependencies
if: steps.cache-primes.outputs.cache-hit != 'true'
run: npm ci --include=dev
################################################################################################
# lint source code using ESlint and Typescript
lint:
needs: install
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: latest
- name: Cache node modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-node-
- name: Lint project
run: npm run lint
################################################################################################
# prepare docker built
# extract the next version tag
prepare-docker-build:
needs: install
runs-on: ubuntu-latest
outputs:
NEXT_VERSION: ${{ steps.set-env.outputs.NEXT_VERSION }}
PUBLISH: ${{ steps.set-env.outputs.PUBLISH }}
BUILD_DATE: ${{ steps.set-env.outputs.BUILD_DATE }}
GIT_SHA: ${{ steps.set-env.outputs.GIT_SHA }}
GIT_REF: ${{ steps.set-env.outputs.GIT_REF }}
new-release-published: ${{ steps.get-next-version.outputs.new-release-published }}
new-release-version: ${{ steps.get-next-version.outputs.new-release-version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: latest
- name: Cache node modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-node-
- name: Extract next semantic-release version
# run: npx semantic-release --dry-run --branches="*"
run: npx semantic-release --dry-run
id: get-next-version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# needed in case semantic-release doesn't run on branches other than 'master' or 'development'
- name: Set NEXT_VERSION if there's NO new release
if: |
steps.get-next-version.outputs.new-release-published == '' ||
steps.get-next-version.outputs.new-release-published == 'false'
run: |
node -p "require('./package').version"
node -p "require('./package').version" | awk '{print "NEXT_VERSION=" $1}' >> "$GITHUB_ENV"
echo "PUBLISH=false" >> "$GITHUB_ENV"
- name: Set NEXT_VERSION if there's a NEW release
if: steps.get-next-version.outputs.new-release-published == 'true'
run: |
echo ${{ steps.get-next-version.outputs.new-release-version }}
echo "NEXT_VERSION=${{ steps.get-next-version.outputs.new-release-version }}" >> "$GITHUB_ENV"
echo "PUBLISH=true" >> "$GITHUB_ENV"
- name: Set Environment Variables
id: set-env
run: |
{
echo "NEXT_VERSION=$NEXT_VERSION"
echo "PUBLISH=$PUBLISH"
echo "BUILD_DATE=$(date +'%Y-%m-%d %H:%M:%S')"
echo "GIT_SHA=$(echo ${{ github.sha }} | cut -c1-7)"
# replace `/` with `-`
# mainly used for branches created by dependabot. they contain `/` which docker tagname cannot have
# https://docs.docker.com/engine/reference/commandline/tag/#description
# https://stackoverflow.com/a/73799519/3053548
# https://stackoverflow.com/a/73467468/3053548
echo "GIT_REF=${GITHUB_REF_NAME//\//-}"
# echo "GHCR_IMAGE=$(echo 'console.log("ghcr.io/${{ github.repository }}".toLowerCase())' | node -)" >> $GITHUB_ENV
} | tee -a "$GITHUB_ENV" "$GITHUB_OUTPUT"
- run: echo "$GITHUB_ENV"
################################################################################################
# build docker images using reusable workflow and github action matrix
docker-build-image:
needs: prepare-docker-build
strategy:
matrix:
# using paired matrix values
# obtained from
# https://stackoverflow.com/a/76547617/3053548
include:
- version: latest
publish: ${{ needs.prepare-docker-build.outputs.publish == 'true' }}
# next version
- version: ${{ needs.prepare-docker-build.outputs.next_version }}
publish: ${{ needs.prepare-docker-build.outputs.publish == 'true' }}
# nightly
- version: nightly
publish: ${{ github.ref == 'refs/heads/development' }}
# branches that are not `development` or `master`
# used for testing code of development branches
- version: ${{ needs.prepare-docker-build.outputs.git_ref }}
publish: ${{ github.ref != 'refs/heads/development' && github.ref != 'refs/heads/master' && github.actor != 'dependabot[bot]' }}
uses: ./.github/workflows/reusable-docker-build.yml
with:
publish: ${{ matrix.publish }}
tags: ${{ matrix.version }}
secrets: inherit
################################################################################################
# verify matrix job results
# since branch protection rules can't group the job matrix together as a required status check.
# this will serve as a workaround
# code obtained from
# - https://github.com/orgs/community/discussions/26822#discussioncomment-5122101
matrix-results:
needs: docker-build-image
runs-on: ubuntu-latest
name: verify job matrix results
if: always()
steps:
- run: exit 1
# see https://stackoverflow.com/a/67532120/4907315
if: >-
${{
contains(needs.*.result, 'failure')
|| contains(needs.*.result, 'cancelled')
}}
################################################################################################
semantic-release:
# prerequisite of a job that uses matrix
# https://github.com/orgs/community/discussions/42010#discussioncomment-4439644
needs: docker-build-image
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/development'
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-node@v4
with:
node-version: latest
- name: Cache node modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-node-
- run: npm install --production=false
- name: semantic-release
run: npx semantic-release --ci
env:
GITHUB_TOKEN: ${{ secrets.DEPENDABOT_TOKEN }}
####################################################################################################