Skip to content

Publish to Docker only if repo name is boilerplate project #50

Publish to Docker only if repo name is boilerplate project

Publish to Docker only if repo name is boilerplate project #50

Workflow file for this run

name: Pipeline
on:
pull_request:
push:
branches: ["*"]
jobs:
check:
name: Check formatting with Prettier
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- uses: oven-sh/setup-bun@v2
env:
HUSKY: 0
- run: bun install --frozen-lockfile
- uses: creyD/[email protected]
with:
prettier_options: --check .
dry: true
only_changed: true
publish:
name: Publish to Docker Hub
needs: check
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.repository == '*/*-app-boilerplate'
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- name: Extract project metadata
env:
AUTHOR: ${{ vars.DOCKER_HUB_USERNAME }}
GITHUB_REPOSITORY: ${{ env.GITHUB_REPOSITORY }}
run: |
SEMVER=$(jq ".version" package.json | tr -d '"')
declare -a versions=()
declare -a split_by_slash=()
IFS='.' read -ra versions <<< "$SEMVER"
IFS="/" read -ra split_by_slash <<< "$GITHUB_REPOSITORY"
echo "SEMVER=$SEMVER" >> "$GITHUB_ENV"
echo "MAJOR=${versions[0]}" >> "$GITHUB_ENV"
echo "MINOR=${versions[1]}" >> "$GITHUB_ENV"
echo "AUTHOR=${AUTHOR:-split_by_slash[0]}" >> "$GITHUB_ENV"
echo "DEVELOPMENT=$GITHUB_REPOSITORY:development" >> "$GITHUB_ENV"
echo "PRODUCTION=$GITHUB_REPOSITORY:production" >> "$GITHUB_ENV"
- uses: docker/setup-buildx-action@v3
name: Setup Docker Buildx
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ env.AUTHOR }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Publish development tags
uses: docker/build-push-action@v6
with:
context: .devcontainer/
push: true
tags: ${{ env.DEVELOPMENT }},${{ env.DEVELOPMENT }}-${{ env.MAJOR }},${{ env.DEVELOPMENT }}-${{ env.MAJOR }}.${{ env.MINOR }},${{ env.DEVELOPMENT }}-${{ env.SEMVER }}
- name: Publish production tags
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ env.PRODUCTION }},${{ env.PRODUCTION }}-${{ env.MAJOR }},${{ env.PRODUCTION }}-${{ env.MAJOR }}.${{ env.MINOR }},${{ env.PRODUCTION }}-${{ env.SEMVER }}