This repository has been archived by the owner on Dec 3, 2023. It is now read-only.
Merge pull request #309 from sebbo2002/depfu/batch_dev/npm/2023-11-28 #933
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test & Release | |
on: | |
push: | |
branches-ignore: | |
- 'gh-pages' | |
- 'depfu/**' | |
- 'dependabot/**' | |
- 'template-updater/**' | |
pull_request: null | |
jobs: | |
tests: | |
name: Unit Tests | |
runs-on: ubuntu-latest | |
if: github.repository != 'sebbo2002/js-template' && (contains(toJson(github.event.commits.*.message), '[skip ci]') == false || github.ref == 'refs/heads/main') | |
strategy: | |
matrix: | |
node: [18.x, 20.x, current] | |
steps: | |
- name: ☁️ Checkout Project | |
uses: actions/checkout@v4 | |
- name: 🔧 Setup node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node }} | |
cache: 'npm' | |
- name: 📦 Install dependencies | |
run: npm ci | |
- name: ⏳ Run tests | |
run: npm run test | |
coverage: | |
name: Code Coverage / Lint | |
runs-on: ubuntu-latest | |
if: github.repository != 'sebbo2002/js-template' && (contains(toJson(github.event.commits.*.message), '[skip ci]') == false || github.ref == 'refs/heads/main') | |
steps: | |
- name: ☁️ Checkout Project | |
uses: actions/checkout@v4 | |
- name: 🔧 Setup node.js | |
uses: actions/setup-node@v4 | |
with: | |
cache: 'npm' | |
- name: 📦 Install dependencies | |
run: npm ci | |
- name: 🔍 Run linter | |
run: npm run lint | |
- name: ⚙️ Build project | |
run: npm run build-all | |
license-checker: | |
name: License Checker | |
runs-on: ubuntu-latest | |
if: contains(toJson(github.event.commits.*.message), '[skip ci]') == false || github.ref == 'refs/heads/main' | |
steps: | |
- name: ☁️ Checkout Project | |
uses: actions/checkout@v4 | |
- name: 🔧 Setup node.js | |
uses: actions/setup-node@v4 | |
with: | |
cache: 'npm' | |
- name: 📦 Install dependencies | |
run: npm ci | |
- name: 🕵️♀️ Run license checker | |
run: npm run license-check | |
docker-image: | |
name: Build Docker Image | |
runs-on: ubuntu-latest | |
env: | |
PUSH_TO_DOCKERHUB: ${{ (github.repository != 'sebbo2002/js-template') && (secrets.DOCKERHUB_TOKEN != null) }} | |
steps: | |
- name: ☁️ Checkout | |
uses: actions/checkout@v4 | |
- name: 🔧 Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: 🔧 Set up Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@master | |
- name: 🔐 Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: 🔐 Login to DockerHub | |
uses: docker/login-action@v3 | |
if: ${{ env.PUSH_TO_DOCKERHUB == 'true' }} | |
with: | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: ℹ️ Set Build Variables | |
id: buildVars | |
run: echo "date=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_OUTPUT | |
- name: 🪄 Build and push (1/2) | |
uses: docker/build-push-action@v5 | |
continue-on-error: true | |
id: docker-build-1-1 | |
with: | |
context: . | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
target: build-container | |
builder: ${{ steps.buildx.outputs.name }} | |
platforms: linux/amd64,linux/arm/v7,linux/arm/v6 | |
pull: true | |
push: true | |
tags: ghcr.io/${{ github.repository }}:build-container-${{ hashFiles('package*.json') }} | |
cache-from: ghcr.io/${{ github.repository }}:build-container-${{ hashFiles('package*.json') }} | |
cache-to: type=inline | |
- name: 🪄 Build and push (1/2, second try) | |
uses: docker/build-push-action@v5 | |
continue-on-error: true | |
if: steps.docker-build-1-1.outcome=='failure' | |
id: docker-build-1-2 | |
with: | |
context: . | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
target: build-container | |
builder: ${{ steps.buildx.outputs.name }} | |
platforms: linux/amd64,linux/arm/v7,linux/arm/v6 | |
pull: true | |
push: true | |
tags: ghcr.io/${{ github.repository }}:build-container-${{ hashFiles('package*.json') }} | |
cache-from: ghcr.io/${{ github.repository }}:build-container-${{ hashFiles('package*.json') }} | |
cache-to: type=inline | |
- name: 🪄 Build and push (1/2, third try) | |
uses: docker/build-push-action@v5 | |
continue-on-error: true | |
if: steps.docker-build-1-2.outcome=='failure' | |
id: docker-build-1-3 | |
with: | |
context: . | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
target: build-container | |
builder: ${{ steps.buildx.outputs.name }} | |
platforms: linux/amd64,linux/arm/v7,linux/arm/v6 | |
pull: true | |
push: true | |
tags: ghcr.io/${{ github.repository }}:build-container-${{ hashFiles('package*.json') }} | |
cache-from: ghcr.io/${{ github.repository }}:build-container-${{ hashFiles('package*.json') }} | |
cache-to: type=inline | |
- name: 🪄 Build and push (1/2; Summary) | |
if: always() | |
run: | | |
if ${{ steps.docker-build-1-1.outcome=='success' || steps.docker-build-1-2.outcome=='success' || steps.docker-build-1-3.outcome=='success' }}; then | |
echo "🎉 Whoop whoop, that worked…" | |
else | |
exit 1 | |
fi | |
- name: 🪄 Build and push (2/2) | |
uses: docker/build-push-action@v5 | |
continue-on-error: true | |
id: docker-build-2-1 | |
with: | |
context: . | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
builder: ${{ steps.buildx.outputs.name }} | |
platforms: linux/amd64,linux/arm/v7,linux/arm/v6 | |
pull: true | |
push: true | |
tags: | | |
ghcr.io/${{ github.repository }}:${{ github.sha }} | |
ghcr.io/${{ github.repository }}:cache-${{ hashFiles('package*.json') }} | |
labels: | | |
org.opencontainers.image.authors=${{ github.repository_owner }} | |
org.opencontainers.image.created=${{ steps.buildVars.outputs.date }} | |
org.opencontainers.image.ref.name=${{ github.ref }} | |
org.opencontainers.image.revision=${{ github.sha }} | |
org.opencontainers.image.source=https://github.com/${{ github.repository }} | |
cache-from: | | |
ghcr.io/${{ github.repository }}:build-container-${{ hashFiles('package*.json') }} | |
ghcr.io/${{ github.repository }}:cache-${{ hashFiles('package*.json') }} | |
ghcr.io/${{ github.repository }}:next | |
- name: 🪄 Build and push (2/2; second try) | |
uses: docker/build-push-action@v5 | |
continue-on-error: true | |
if: steps.docker-build-2-1.outcome=='failure' | |
id: docker-build-2-2 | |
with: | |
context: . | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
builder: ${{ steps.buildx.outputs.name }} | |
platforms: linux/amd64,linux/arm/v7,linux/arm/v6 | |
pull: true | |
push: true | |
tags: | | |
ghcr.io/${{ github.repository }}:${{ github.sha }} | |
ghcr.io/${{ github.repository }}:cache-${{ hashFiles('package*.json') }} | |
labels: | | |
org.opencontainers.image.authors=${{ github.repository_owner }} | |
org.opencontainers.image.created=${{ steps.buildVars.outputs.date }} | |
org.opencontainers.image.ref.name=${{ github.ref }} | |
org.opencontainers.image.revision=${{ github.sha }} | |
org.opencontainers.image.source=https://github.com/${{ github.repository }} | |
cache-from: | | |
ghcr.io/${{ github.repository }}:build-container-${{ hashFiles('package*.json') }} | |
ghcr.io/${{ github.repository }}:cache-${{ hashFiles('package*.json') }} | |
ghcr.io/${{ github.repository }}:next | |
- name: 🪄 Build and push (2/2; third try) | |
uses: docker/build-push-action@v5 | |
if: steps.docker-build-2-2.outcome=='failure' | |
continue-on-error: true | |
id: docker-build-2-3 | |
with: | |
context: . | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
builder: ${{ steps.buildx.outputs.name }} | |
platforms: linux/amd64,linux/arm/v7,linux/arm/v6 | |
pull: true | |
push: true | |
tags: | | |
ghcr.io/${{ github.repository }}:${{ github.sha }} | |
ghcr.io/${{ github.repository }}:cache-${{ hashFiles('package*.json') }} | |
labels: | | |
org.opencontainers.image.authors=${{ github.repository_owner }} | |
org.opencontainers.image.created=${{ steps.buildVars.outputs.date }} | |
org.opencontainers.image.ref.name=${{ github.ref }} | |
org.opencontainers.image.revision=${{ github.sha }} | |
org.opencontainers.image.source=https://github.com/${{ github.repository }} | |
cache-from: | | |
ghcr.io/${{ github.repository }}:build-container-${{ hashFiles('package*.json') }} | |
ghcr.io/${{ github.repository }}:cache-${{ hashFiles('package*.json') }} | |
ghcr.io/${{ github.repository }}:next | |
cache-to: type=inline | |
- name: 🪄 Build and push (2/2; Summary) | |
if: always() | |
id: docker-build-2 | |
run: | | |
if ${{ steps.docker-build-2-1.outcome=='success' }}; then | |
echo "🎉 Whoop whoop, that worked (first try)" | |
echo "::set-output name=digest::${{ steps.docker-build-2-1.outputs.digest }}" | |
elif ${{ steps.docker-build-2-2.outcome=='success' }}; then | |
echo "🎉 Whoop whoop, that worked (second try)" | |
echo "::set-output name=digest::${{ steps.docker-build-2-2.outputs.digest }}" | |
elif ${{ steps.docker-build-2-3.outcome=='success' }}; then | |
echo "🎉 Whoop whoop, that worked (third try)" | |
echo "::set-output name=digest::${{ steps.docker-build-2-3.outputs.digest }}" | |
else | |
exit 1 | |
fi | |
- name: 🔄 Push container to DockerHub | |
id: docker-build-dh | |
if: ${{ env.PUSH_TO_DOCKERHUB == 'true' }} | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
builder: ${{ steps.buildx.outputs.name }} | |
platforms: linux/amd64,linux/arm/v7,linux/arm/v6 | |
push: true | |
tags: | | |
${{ github.repository }}:${{ github.sha }} | |
labels: | | |
org.opencontainers.image.authors=${{ github.repository_owner }} | |
org.opencontainers.image.created=${{ steps.buildVars.outputs.date }} | |
org.opencontainers.image.ref.name=${{ github.ref }} | |
org.opencontainers.image.revision=${{ github.sha }} | |
org.opencontainers.image.source=https://github.com/${{ github.repository }} | |
cache-from: | | |
ghcr.io/${{ github.repository }}:${{ github.sha }} | |
ghcr.io/${{ github.repository }}:cache-${{ hashFiles('package*.json') }} | |
ghcr.io/${{ github.repository }}:build-container-${{ hashFiles('package*.json') }} | |
cache-to: type=inline | |
outputs: | |
digest-gh: ${{ steps.docker-build-2.outputs.digest }} | |
digest-dh: ${{ steps.docker-build-dh.outputs.digest }} | |
release: | |
name: Release | |
runs-on: ubuntu-latest | |
concurrency: release | |
env: | |
PUSH_TO_DOCKERHUB: ${{ (github.repository != 'sebbo2002/js-template') && (secrets.DOCKERHUB_TOKEN != null) }} | |
permissions: | |
contents: write | |
issues: write | |
packages: write | |
pull-requests: write | |
id-token: write | |
needs: | |
- coverage | |
- tests | |
- license-checker | |
- docker-image | |
if: ${{ github.repository != 'sebbo2002/js-template' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop') }} | |
steps: | |
- name: ☁️ Checkout Project | |
uses: actions/checkout@v4 | |
- name: 🔧 Setup node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20.x | |
cache: 'npm' | |
- name: 🔧 Setup regclient | |
run: | | |
mkdir -p "$HOME/.local/bin" | |
curl -L https://github.com/regclient/regclient/releases/latest/download/regctl-linux-amd64 > "$HOME/.local/bin/regctl" | |
chmod +x "$HOME/.local/bin/regctl" | |
echo "$HOME/.local/bin" >> $GITHUB_PATH | |
- name: 📦 Install dependencies | |
run: npm ci | |
- name: 📂 Create docs folder | |
run: mkdir ./docs | |
- name: 🔐 Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: 🔐 Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: 🪄 Run semantic-release | |
run: BRANCH=${GITHUB_REF#refs/heads/} npx semantic-release | |
env: | |
GH_REPO: ${{ github.repository }} | |
GH_TOKEN: ${{ secrets.GH_TOKEN }} | |
GH_OWNER: ${{ github.repository_owner }} | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
NPM_CONFIG_PROVENANCE: true | |
DOCKER_LOCAL_IMAGE_GH: ghcr.io/${{ github.repository }}:${{ github.sha }} | |
DOCKER_LOCAL_IMAGE_DH: ${{ github.repository }}:${{ github.sha }} | |
- name: 🔃 Merge main back into develop | |
if: ${{ github.ref == 'refs/heads/main' }} | |
uses: everlytic/branch-merge@1.1.5 | |
with: | |
github_token: ${{ secrets.GH_TOKEN }} | |
source_ref: 'main' | |
target_branch: 'develop' | |
commit_message_template: 'Merge branch {source_ref} into {target_branch} [skip ci]' |