Skip to content

Commit afe3766

Browse files
jfrochesamrose
authored andcommitted
feat: add branch-based versioning for PR AMI builds
Manually create unique Postgres version names in branch often leads to version conflicts with the base branch versions. These conflicts force developers to deal with manual conflict resolution and unnecessary rebuilds. To address this, this change implement automatic branch-based versioning for AMI builds triggered via workflow_dispatch on non-develop and non-release branches. The branch name is sanitized and appended to the Postgres version string. Example: Branch 'multi-version-ext/pg-partman' produces postgres version 'multi-version-ext-pg-partman'
1 parent d383df0 commit afe3766

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

.github/workflows/ami-release-nix.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,20 @@ jobs:
6767
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
6868
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
6969
70-
- name: Run checks if triggered manually
71-
if: ${{ github.event_name == 'workflow_dispatch' }}
72-
run: |
73-
SUFFIX=$(nix run nixpkgs#yq -- ".postgres_release[\"postgres${{ matrix.postgres_version }}\"]" ansible/vars.yml | sed -E 's/[0-9\.]+(.*)$/\1/')
74-
if [[ -z "$SUFFIX" ]] ; then
75-
echo "Version must include non-numeric characters if built manually."
76-
exit 1
77-
fi
78-
7970
- name: Set PostgreSQL version environment variable
8071
run: |
8172
echo "POSTGRES_MAJOR_VERSION=${{ matrix.postgres_version }}" >> $GITHUB_ENV
8273
echo "EXECUTION_ID=${{ github.run_id }}-${{ matrix.postgres_version }}" >> $GITHUB_ENV
8374
8475
- name: Generate common-nix.vars.pkr.hcl
8576
run: |
86-
PG_VERSION=$(nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
87-
PG_VERSION=$(echo "$PG_VERSION" | tr -d '"') # Remove any surrounding quotes
77+
PG_VERSION="$(nix run nixpkgs#yq -- -r '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)"
78+
BRANCH_NAME="$(echo "${{ github.ref }}" | sed 's|refs/heads/||')"
79+
if [[ "${{ github.event_name }}" == "workflow_dispatch" && "$BRANCH_NAME" != "develop" && "$BRANCH_NAME" != release/* ]]; then
80+
SUFFIX="${BRANCH_NAME//[^a-zA-Z0-9._-]/-}"
81+
PG_VERSION="${PG_VERSION}-${SUFFIX}"
82+
echo "Added branch suffix to version: $SUFFIX"
83+
fi
8884
echo 'postgres-version = "'$PG_VERSION'"' > common-nix.vars.pkr.hcl
8985
# Ensure there's a newline at the end of the file
9086
echo "" >> common-nix.vars.pkr.hcl

0 commit comments

Comments
 (0)