From 49b6c899b0463ce91723cc70e6cf460879aa4609 Mon Sep 17 00:00:00 2001 From: Marty Byrde <45905689+Marty-Byrde@users.noreply.github.com> Date: Mon, 27 Oct 2025 20:34:21 +0100 Subject: [PATCH 1/5] ci: introduced check-file composite action This action is a reworked, improved and more generic version of the already existing check-changed-files action. It essentially checks whether the files that were changed within a commit-range match a given regex-pattern. --- .github/actions/file-change/action.yml | 56 ++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .github/actions/file-change/action.yml diff --git a/.github/actions/file-change/action.yml b/.github/actions/file-change/action.yml new file mode 100644 index 000000000..3f357a45e --- /dev/null +++ b/.github/actions/file-change/action.yml @@ -0,0 +1,56 @@ +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 + 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.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 }} From 0b0b6bb33ab958a9e39f79dd0cf3ec3347c287e1 Mon Sep 17 00:00:00 2001 From: Marty Byrde <45905689+Marty-Byrde@users.noreply.github.com> Date: Mon, 27 Oct 2025 20:38:14 +0100 Subject: [PATCH 2/5] ci: applied check-file composite action in workflows This way the checking of whether or not the database schema has been changed is done by the composite-action, reducing code duplication. --- .github/workflows/build-db-docker-image.yml | 27 ++++++--------------- .github/workflows/semantic-versioning.yml | 24 +++++------------- 2 files changed, 13 insertions(+), 38 deletions(-) diff --git a/.github/workflows/build-db-docker-image.yml b/.github/workflows/build-db-docker-image.yml index 080910c50..dc3a0eccc 100644 --- a/.github/workflows/build-db-docker-image.yml +++ b/.github/workflows/build-db-docker-image.yml @@ -15,7 +15,7 @@ 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 @@ -23,26 +23,13 @@ jobs: 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:-}..${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" build-db-image: runs-on: ubuntu-latest diff --git a/.github/workflows/semantic-versioning.yml b/.github/workflows/semantic-versioning.yml index 81961c749..ab79e2dc1 100644 --- a/.github/workflows/semantic-versioning.yml +++ b/.github/workflows/semantic-versioning.yml @@ -153,25 +153,13 @@ 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:-}..${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" build-db-image: runs-on: ubuntu-latest From 035c5f86212b504778561816908bd301587c6ae6 Mon Sep 17 00:00:00 2001 From: Marty Byrde <45905689+Marty-Byrde@users.noreply.github.com> Date: Wed, 29 Oct 2025 20:41:40 +0100 Subject: [PATCH 3/5] ci: added input to file-change action By adding the `consider_initial_commit_relevant` input one can specify whether the initial commit to a branch is considered as a change or not. --- .github/actions/file-change/action.yml | 6 +++++- .github/workflows/build-db-docker-image.yml | 1 + .github/workflows/semantic-versioning.yml | 10 +++++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/actions/file-change/action.yml b/.github/actions/file-change/action.yml index 3f357a45e..c86f9a1a0 100644 --- a/.github/actions/file-change/action.yml +++ b/.github/actions/file-change/action.yml @@ -12,6 +12,10 @@ inputs: 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' @@ -23,7 +27,7 @@ runs: - run: | set -euo pipefail # For a new branch or initial commit, treat as relevant - if [ "${{ inputs.base_commit }}" = "" ] || [ "${{ inputs.base_commit }}" = "0000000000000000000000000000000000000000" ]; then + 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 diff --git a/.github/workflows/build-db-docker-image.yml b/.github/workflows/build-db-docker-image.yml index dc3a0eccc..5b9310e2b 100644 --- a/.github/workflows/build-db-docker-image.yml +++ b/.github/workflows/build-db-docker-image.yml @@ -30,6 +30,7 @@ jobs: 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 diff --git a/.github/workflows/semantic-versioning.yml b/.github/workflows/semantic-versioning.yml index ab79e2dc1..6cd333b46 100644 --- a/.github/workflows/semantic-versioning.yml +++ b/.github/workflows/semantic-versioning.yml @@ -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 @@ -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 @@ -160,6 +163,7 @@ jobs: 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 From 2622c03dbbd8bcf074209bbdb7a1280800a4b35a Mon Sep 17 00:00:00 2001 From: Marty Byrde <45905689+Marty-Byrde@users.noreply.github.com> Date: Fri, 31 Oct 2025 16:40:37 +0100 Subject: [PATCH 4/5] ci: removed fallback-tags in compute-db-image-tags The reason for the removal of fallback-tags for the main and canary branch, when there are no available tags, is that the existence of tags is required. Hence, in case there are none an error should be displayed instead of following the branch-tag format --- .github/actions/compute-db-image-tags/action.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/actions/compute-db-image-tags/action.yml b/.github/actions/compute-db-image-tags/action.yml index c42e65fcb..8e57de8cf 100644 --- a/.github/actions/compute-db-image-tags/action.yml +++ b/.github/actions/compute-db-image-tags/action.yml @@ -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) @@ -75,10 +73,8 @@ 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 ;; *) From 5a586987ac1a97e2c3e9aac80c641f5873e7d9ab Mon Sep 17 00:00:00 2001 From: Marty Byrde <45905689+Marty-Byrde@users.noreply.github.com> Date: Fri, 31 Oct 2025 16:43:07 +0100 Subject: [PATCH 5/5] ci: added latest tag to feature-branch in compute-db-image tag The reason for this is that this way the current implementation of initializing the respective database service works. Unless a new image is published while the code-changes that were made along side the schema changes are not merged. --- .github/actions/compute-db-image-tags/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/compute-db-image-tags/action.yml b/.github/actions/compute-db-image-tags/action.yml index 8e57de8cf..084d068e7 100644 --- a/.github/actions/compute-db-image-tags/action.yml +++ b/.github/actions/compute-db-image-tags/action.yml @@ -78,8 +78,8 @@ runs: 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