Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions .github/actions/compute-db-image-tags/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ runs:
add_tag "stable"
add_tag "latest"
else
add_tag "${BRANCH}-${SHA_SHORT}"
add_tag "stable"
add_tag "latest"
WARNING="Failed to retrieve latest-tag on main; fell back to SHA ${SHA_SHORT}"
exit 1;
fi
;;
canary)
Expand All @@ -75,15 +73,13 @@ runs:
add_tag "canary"
add_tag "latest"
else
add_tag "${BRANCH}-${SHA_SHORT}"
add_tag "canary"
add_tag "latest"
WARNING="Failed to retrieve latest-tag on canary; fell back to SHA ${SHA_SHORT}"
exit 1;
fi
;;
*)
# Feature branches: SHA only
add_tag "${BRANCH}-${SHA_SHORT}"
add_tag "latest" # --> may cause issues for other branches that use the latest db-image, e.g. when the schema was changed in another branch
;;
esac

Expand Down
60 changes: 60 additions & 0 deletions .github/actions/file-change/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Check for File Change
description: 'Checks whether a commit has modified files that match a given regex pattern.'

inputs:
base_commit:
description: 'The base_commit commit to compare against. When left empty "" it will assume its a new branch or initial commit and set `changed` to true.'
required: true
newest_commit:
description: The newest commit that the base is compared against
default: ${{ github.sha }}
required: false
regex_pattern:
description: 'Used to determinate if a file was modified within the commit-range; when it matches the pattern'
required: true
consider_initial_commit_relevant:
description: 'When set to true the output will be set to true when the base_commit is empty or an initial-commit. When set to false an initial / empty commit will not be considered relevant as a change.'
required: false
default: 'false'
skip:
description: 'When set to true, the action will always return changed=true'
default: '0'
required: false

runs:
using: 'composite'
steps:
- run: |
set -euo pipefail
# For a new branch or initial commit, treat as relevant
if [ "${{ inputs.consider_initial_commit_relevant }}" = "true" ] && { [ "${{ inputs.base_commit }}" = "" ] || [ "${{ inputs.base_commit }}" = "0000000000000000000000000000000000000000" ]; }; then
echo "New branch or initial commit. Considering changes relevant."
echo "changed=true" >> $GITHUB_OUTPUT
else
CHANGED_FILES=$(git diff --name-only ${{ inputs.base_commit }} ${{ inputs.newest_commit || github.sha }})

printf "Changed files: \n%s\n\n" "$CHANGED_FILES"

MATCHED_FILES=$(printf '%s\n' "$CHANGED_FILES" | grep -E "${{ inputs.regex_pattern }}" || true)
if [ -n "$MATCHED_FILES" ]; then
echo "Files matching regex '${{ inputs.regex_pattern }}':"
printf '%s\n' "$MATCHED_FILES"
echo "File change(s) were detected. Setting output `changed` to true."
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "No changes detected."
echo "changed=false" >> "$GITHUB_OUTPUT"
fi
fi

if [ "${{ inputs.skip }}" = "1" ] || [ "${{ inputs.skip }}" = "true" ]; then
echo "File matching has been overridden. Setting `changed` to true."
echo "changed=true" >> $GITHUB_OUTPUT
fi
shell: bash
id: check

outputs:
changed:
description: 'Whether relevant file changes were detected'
value: ${{ steps.check.outputs.changed }}
28 changes: 8 additions & 20 deletions .github/workflows/build-db-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,22 @@ jobs:
runs-on: ubuntu-latest
name: "Check for Database Schema Update"
outputs:
db_changed: ${{ steps.changed.outputs.db_changed }}
db_changed: ${{ steps.changed.outputs.changed }}

steps:
- name: Checkout with tags
uses: actions/checkout@v4
with:
fetch-depth: 0

# Did init.sql change ? (all commits included in the push)
- name: Check if database/init.sql changed in this push
- name: Check for Schema Changes
id: changed
shell: bash
run: |
set -euo pipefail
BASE="${{ github.event.before }}"
HEAD="${{ github.sha }}"
# Fallback for cases where 'before' may be empty (e.g. first push)
if [ -z "$BASE" ] || ! git cat-file -e "$BASE^{commit}" 2>/dev/null; then
BASE="$(git rev-parse "${HEAD}^" 2>/dev/null || true)"
fi
echo "Diff range: ${BASE:-<none>}..${HEAD}"
if [ -n "$BASE" ] && git diff --name-only "$BASE" "$HEAD" | grep -qx 'database/init.sql'; then
echo "db_changed=true" >> "$GITHUB_OUTPUT"
echo "Database schema (init.sql) has changed."
else
echo "db_changed=false" >> "$GITHUB_OUTPUT"
echo "Database schema (init.sql) has **not** changed. Aborting."
fi
uses: ./.github/actions/file-change
with:
base_commit: ${{ github.event.before }}
newest_commit: ${{ github.sha }}
regex_pattern: "drizzle/*/schema.ts"
consider_initial_commit_relevant: false

build-db-image:
runs-on: ubuntu-latest
Expand Down
34 changes: 13 additions & 21 deletions .github/workflows/semantic-versioning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
- canary
workflow_dispatch:

#todo Check what branch is used to decide which database-image-tag to use. On a feature branch who's name matches db-image-tag, on main use stable and on canary use canary, on other feature branches use canary.
#? as for branch-specific docker-tag images: e.g. 'ref/code-improvements' might be re-used and may have docker-images associated with it. -> check if pr has the latest branch-image-tag-commit-sha in its range.

permissions:
contents: write
packages: write
Expand Down Expand Up @@ -100,11 +103,11 @@ jobs:
- name: Set lowercase repository name as environment variable
run: echo "LOWER_REPO_NAME=$(echo ${{ env.REPO_NAME }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV

- name: 'Get Previous tag'
- name: "Get Previous tag"
id: previoustag
uses: 'WyriHaximus/github-action-get-previous-tag@v1'
uses: "WyriHaximus/github-action-get-previous-tag@v1"

- name: 'Store Version Information'
- name: "Store Version Information"
run: |
echo "{ \"version\": \"${{ steps.previoustag.outputs.tag }}\" }" > ./public/version.json

Expand Down Expand Up @@ -153,25 +156,14 @@ jobs:
fetch-depth: 0

# Did init.sql change ? (all commits included in the push)
- name: Check if database/init.sql changed in this push
- name: Check for Schema Changes
id: changed
shell: bash
run: |
set -euo pipefail
BASE="${{ github.event.before }}"
HEAD="${{ github.sha }}"
# Fallback for cases where 'before' may be empty (e.g. first push)
if [ -z "$BASE" ] || ! git cat-file -e "$BASE^{commit}" 2>/dev/null; then
BASE="$(git rev-parse "${HEAD}^" 2>/dev/null || true)"
fi
echo "Diff range: ${BASE:-<none>}..${HEAD}"
if [ -n "$BASE" ] && git diff --name-only "$BASE" "$HEAD" | grep -qx 'database/init.sql'; then
echo "db_changed=true" >> "$GITHUB_OUTPUT"
echo "Database schema (init.sql) has changed."
else
echo "db_changed=false" >> "$GITHUB_OUTPUT"
echo "Database schema (init.sql) has **not** changed. Aborting."
fi
uses: ./.github/actions/file-change
with:
base_commit: ${{ github.event.before }}
newest_commit: ${{ github.sha }}
regex_pattern: "drizzle/*/schema.ts"
consider_initial_commit_relevant: false

build-db-image:
runs-on: ubuntu-latest
Expand Down
Loading