Skip to content

Merge pull request #112 from BehindTheMusicTree/release/v2.2.7 #248

Merge pull request #112 from BehindTheMusicTree/release/v2.2.7

Merge pull request #112 from BehindTheMusicTree/release/v2.2.7 #248

Workflow file for this run

# yaml-language-server: $schema=https://gist.githubusercontent.com/sargunv/c2ca41a08391cd06feaad97aece309e4/raw/empty-json-schema.json
# Single publish: version tag (prerelease → TEST + staging; release → PROD + production). Manual dispatch from main still uses VERSION + staging.
name: Publish
on:
workflow_call:
workflow_dispatch:
push:
tags:
- "v*"
permissions:
contents: read
packages: write
jobs:
determine-version:
name: Determine version
runs-on: ubuntu-latest
outputs:
app_version: ${{ steps.version.outputs.app_version }}
image_tag: ${{ steps.version.outputs.image_tag }}
env: ${{ steps.version.outputs.env }}
deployment_environment: ${{ steps.version.outputs.deployment_environment }}
steps:
- name: Checkout code
if: ${{ github.ref != 'refs/heads/main' && !startsWith(github.ref, 'refs/tags/') }}
uses: actions/checkout@v5.0.1
with:
fetch-depth: 0
- name: Checkout for main branch
if: github.ref == 'refs/heads/main'
uses: actions/checkout@v5.0.1
with:
fetch-depth: 0
- name: Set version and environment
id: version
run: |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
VERSION="${GITHUB_REF#refs/tags/v}"
if [[ "$VERSION" == *-* ]]; then
{
echo "app_version=$VERSION"
echo "image_tag=$VERSION"
echo "env=staging"
echo "deployment_environment=STAGING"
} >> "$GITHUB_OUTPUT"
echo "Prerelease/dev tag -> STAGING, staging"
else
{
echo "app_version=$VERSION"
echo "image_tag=$VERSION"
echo "env=prod"
echo "deployment_environment=PROD"
} >> "$GITHUB_OUTPUT"
echo "Release tag -> PROD, production"
fi
elif [[ "$GITHUB_REF" == refs/heads/main ]]; then
VERSION=$(tr -d '[:space:]' < VERSION)
if [ -z "$VERSION" ]; then
echo "Error: VERSION file is empty or missing."
exit 1
fi
{
echo "app_version=${VERSION}-staging"
echo "image_tag=staging"
echo "env=staging"
echo "deployment_environment=STAGING"
} >> "$GITHUB_OUTPUT"
echo "Main push -> STAGING, staging"
else
echo "Error: Unsupported ref '$GITHUB_REF'."
echo "Only 'main' branch or tags matching 'v*' are supported."
exit 1
fi
build-and-push:
name: Docker image
needs: [determine-version]
uses: ./.github/workflows/build-and-push.yml
with:
app_version: ${{ needs.determine-version.outputs.app_version }}
image_tag: ${{ needs.determine-version.outputs.image_tag }}
environment: ${{ needs.determine-version.outputs.deployment_environment }}
secrets: inherit
check-pinned-tags:
name: Check AFP tag is pinned
runs-on: ubuntu-latest
needs: [determine-version]
environment: ${{ needs.determine-version.outputs.deployment_environment }}
env:
AFP_VERSION: ${{ vars.AFP_VERSION }}
IMAGE_TAGS_POOL_DIR: ${{ vars.IMAGE_TAGS_POOL_DIR }}
BTMT_REDEPLOYMENT_HOOK_ID_BASE: ${{ vars.BTMT_REDEPLOYMENT_HOOK_ID_BASE }}
outputs:
afp_version: ${{ steps.pinned.outputs.afp_version }}
redeployment_hook_id_base: ${{ steps.pinned.outputs.redeployment_hook_id_base }}
steps:
- name: Require deploy vars (set-image-tags-on-server)
run: |
missing=""
[ -z "${IMAGE_TAGS_POOL_DIR}" ] && missing="${missing} IMAGE_TAGS_POOL_DIR"
[ -z "${BTMT_REDEPLOYMENT_HOOK_ID_BASE}" ] && missing="${missing} BTMT_REDEPLOYMENT_HOOK_ID_BASE"
if [ -n "$missing" ]; then
echo "ERROR: Set Variables on this job's GitHub Environment (STAGING or PROD) or at repository/org level:$missing"
echo "Example: IMAGE_TAGS_POOL_DIR=/srv/btmt/image-tags, BTMT_REDEPLOYMENT_HOOK_ID_BASE=... (must match infrastructure)"
exit 1
fi
- name: Require pinned AFP image tag
id: pinned
run: |
missing=""
[ -z "${AFP_VERSION}" ] && missing="${missing} AFP_VERSION"
if [ -n "$missing" ]; then
echo "ERROR: Pinned AFP image tag required (no 'latest'). Set AFP_VERSION in Settings → Variables."
echo "Example: AFP_VERSION=v1.4.4"
exit 1
fi
echo "AFP_VERSION=$AFP_VERSION (DB image is fixed to postgres:16.4 in docker-compose.yml)"
echo "afp_version=$AFP_VERSION" >> "$GITHUB_OUTPUT"
echo "redeployment_hook_id_base=${BTMT_REDEPLOYMENT_HOOK_ID_BASE}" >> "$GITHUB_OUTPUT"
set-image-tags:
name: Set image tags on server
needs: [build-and-push, determine-version, check-pinned-tags]
uses: BehindTheMusicTree/github-workflows/.github/workflows/set-image-tags-on-server.yml@v2.0.0
with:
env: ${{ needs.determine-version.outputs.env }}
stack: btmt
tags: |
HTMT_API_TAG=${{ needs.determine-version.outputs.image_tag }}
DB_TAG=16.4
AFP_TAG=${{ needs.check-pinned-tags.outputs.afp_version }}
release_id: ${{ needs.determine-version.outputs.image_tag }}
release_sha: ${{ github.sha }}
secrets: inherit
redeploy-webhook-call:
name: Redeploy webhook
needs: [build-and-push, set-image-tags, check-pinned-tags, determine-version]
uses: BehindTheMusicTree/github-workflows/.github/workflows/call-redeployment-webhook.yml@v2.0.0
with:
env: ${{ needs.determine-version.outputs.env }}
hook_id_base: ${{ needs.check-pinned-tags.outputs.redeployment_hook_id_base }}
secrets: inherit