Skip to content
Open
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
4 changes: 4 additions & 0 deletions .github/actionlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
self-hosted-runner:
labels:
- blacksmith-2vcpu-ubuntu-2404-arm
- blacksmith-4vcpu-ubuntu-2404
46 changes: 29 additions & 17 deletions .github/workflows/ami-release-nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:
permissions:
contents: write
id-token: write
actions: write

jobs:
prepare:
Expand All @@ -36,7 +37,7 @@ jobs:
id: set-versions
run: |
VERSIONS=$(nix run nixpkgs#yq -- '.postgres_major[]' ansible/vars.yml | nix run nixpkgs#jq -- -R -s -c 'split("\n")[:-1]')
echo "postgres_versions=$VERSIONS" >> $GITHUB_OUTPUT
echo "postgres_versions=$VERSIONS" >> "$GITHUB_OUTPUT"

build:
needs: prepare
Expand Down Expand Up @@ -67,25 +68,21 @@ jobs:
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=

- name: Run checks if triggered manually
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
SUFFIX=$(nix run nixpkgs#yq -- ".postgres_release[\"postgres${{ matrix.postgres_version }}\"]" ansible/vars.yml | sed -E 's/[0-9\.]+(.*)$/\1/')
if [[ -z "$SUFFIX" ]] ; then
echo "Version must include non-numeric characters if built manually."
exit 1
fi

- name: Set PostgreSQL version environment variable
run: |
echo "POSTGRES_MAJOR_VERSION=${{ matrix.postgres_version }}" >> $GITHUB_ENV
echo "EXECUTION_ID=${{ github.run_id }}-${{ matrix.postgres_version }}" >> $GITHUB_ENV
echo "POSTGRES_MAJOR_VERSION=${{ matrix.postgres_version }}" >> "$GITHUB_ENV"
echo "EXECUTION_ID=${{ github.run_id }}-${{ matrix.postgres_version }}" >> "$GITHUB_ENV"

- name: Generate common-nix.vars.pkr.hcl
run: |
PG_VERSION=$(nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
PG_VERSION=$(echo "$PG_VERSION" | tr -d '"') # Remove any surrounding quotes
echo 'postgres-version = "'$PG_VERSION'"' > common-nix.vars.pkr.hcl
PG_VERSION="$(nix run nixpkgs#yq -- -r '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)"
BRANCH_NAME="$(echo "${{ github.ref }}" | sed 's|refs/heads/||')"
if [[ "${{ github.event_name }}" == "workflow_dispatch" && "$BRANCH_NAME" != "develop" && "$BRANCH_NAME" != release/* ]]; then
SUFFIX="${BRANCH_NAME//[^a-zA-Z0-9._-]/-}-${{ github.run_id }}"
PG_VERSION="${PG_VERSION}-${SUFFIX}"
echo "Added branch suffix to version: $SUFFIX"
fi
echo "postgres-version = \"$PG_VERSION\"" > common-nix.vars.pkr.hcl
# Ensure there's a newline at the end of the file
echo "" >> common-nix.vars.pkr.hcl

Expand All @@ -110,8 +107,9 @@ jobs:
- name: Grab release version
id: process_release_version
run: |
VERSION=$(cat common-nix.vars.pkr.hcl | sed -e 's/postgres-version = "\(.*\)"/\1/g')
echo "version=$VERSION" >> $GITHUB_OUTPUT
VERSION=$(sed -e 's/postgres-version = "\(.*\)"/\1/g' common-nix.vars.pkr.hcl)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "::notice title=AMI Published::Postgres AMI version: $VERSION"

- name: Create nix flake revision tarball
run: |
Expand Down Expand Up @@ -171,6 +169,20 @@ jobs:
tag_name: ${{ steps.process_release_version.outputs.version }}
target_commitish: ${{github.sha}}

- name: Trigger pg_upgrade_scripts workflow
env:
GH_TOKEN: ${{ github.token }}
run: |
gh workflow run publish-nix-pgupgrade-scripts.yml \
-f postgresVersion="${{ steps.process_release_version.outputs.version }}"

- name: Trigger pg_upgrade_bin flake version workflow
env:
GH_TOKEN: ${{ github.token }}
run: |
gh workflow run publish-nix-pgupgrade-bin-flake-version.yml \
-f postgresVersion="${{ steps.process_release_version.outputs.version }}"

- name: Slack Notification on Failure
if: ${{ failure() }}
uses: rtCamp/action-slack-notify@v2
Expand Down
18 changes: 13 additions & 5 deletions .github/workflows/publish-nix-pgupgrade-bin-flake-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ jobs:
- name: Set PostgreSQL versions
id: set-versions
run: |
VERSIONS=$(nix run nixpkgs#yq -- '.postgres_major[]' ansible/vars.yml | nix run nixpkgs#jq -- -R -s -c 'split("\n")[:-1]')
if [[ "${{ inputs.postgresVersion }}" != "" ]]; then
MAJOR_VERSION=$(echo "${{ inputs.postgresVersion }}" | cut -d'.' -f1)
VERSIONS="[\"$MAJOR_VERSION\"]"
else
VERSIONS=$(nix run nixpkgs#yq -- '.postgres_major[]' ansible/vars.yml | nix run nixpkgs#jq -- -R -s -c 'split("\n")[:-1]')
fi
echo "postgres_versions=$VERSIONS" >> $GITHUB_OUTPUT

publish-staging:
Expand All @@ -43,10 +48,10 @@ jobs:
- name: Grab release version
id: process_release_version
run: |
VERSION=$(nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
VERSION=$(echo "$VERSION" | tr -d '"') # Remove any surrounding quotes
if [[ "${{ inputs.postgresVersion }}" != "" ]]; then
VERSION="${{ inputs.postgresVersion }}"
else
VERSION=$(nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "major_version=$(echo $VERSION | cut -d'.' -f1)" >> "$GITHUB_OUTPUT"
Expand Down Expand Up @@ -95,8 +100,11 @@ jobs:
- name: Grab release version
id: process_release_version
run: |
VERSION=$(nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
VERSION=$(echo $VERSION | tr -d '"') # Remove any surrounding quotes
if [[ "${{ inputs.postgresVersion }}" != "" ]]; then
VERSION="${{ inputs.postgresVersion }}"
else
VERSION=$(nix run nixpkgs#yq -- -r '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "major_version=$(echo $VERSION | cut -d'.' -f1)" >> "$GITHUB_OUTPUT"

Expand Down
17 changes: 10 additions & 7 deletions .github/workflows/publish-nix-pgupgrade-scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ jobs:
steps:
- name: Checkout Repo
uses: supabase/postgres/.github/actions/shared-checkout@HEAD

- uses: ./.github/actions/nix-install-ephemeral

- name: Set PostgreSQL versions
id: set-versions
run: |
VERSIONS=$(nix run nixpkgs#yq -- '.postgres_major[]' ansible/vars.yml | nix run nixpkgs#jq -- -R -s -c 'split("\n")[:-1]')
if [[ "${{ inputs.postgresVersion }}" != "" ]]; then
MAJOR_VERSION=$(echo "${{ inputs.postgresVersion }}" | cut -d'.' -f1)
VERSIONS="[\"$MAJOR_VERSION\"]"
else
VERSIONS=$(nix run nixpkgs#yq -- '.postgres_major[]' ansible/vars.yml | nix run nixpkgs#jq -- -R -s -c 'split("\n")[:-1]')
fi
echo "postgres_versions=$VERSIONS" >> $GITHUB_OUTPUT

publish-staging:
Expand All @@ -50,10 +53,10 @@ jobs:
- name: Grab release version
id: process_release_version
run: |
VERSION=$(nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
VERSION=$(echo "$VERSION" | tr -d '"') # Remove any surrounding quotes
if [[ "${{ inputs.postgresVersion }}" != "" ]]; then
VERSION="${{ inputs.postgresVersion }}"
else
VERSION=$(nix run nixpkgs#yq -- -r '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"

Expand Down Expand Up @@ -101,10 +104,10 @@ jobs:
- name: Grab release version
id: process_release_version
run: |
VERSION=$(nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
VERSION=$(echo "$VERSION" | tr -d '"') # Remove any surrounding quotes
if [[ "${{ inputs.postgresVersion }}" != "" ]]; then
VERSION="${{ inputs.postgresVersion }}"
else
VERSION=$(nix run nixpkgs#yq -- -r '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"

Expand Down
12 changes: 12 additions & 0 deletions nix/hooks.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{ inputs, ... }:
let
ghWorkflows = builtins.attrNames (builtins.readDir ../.github/workflows);
lintedWorkflows = [ "ami-release-nix.yml" ];
in
{
imports = [ inputs.git-hooks.flakeModule ];
perSystem =
Expand All @@ -8,9 +12,17 @@
check.enable = true;
settings = {
hooks = {
actionlint = {
enable = true;
excludes = builtins.filter (name: !builtins.elem name lintedWorkflows) ghWorkflows;
verbose = true;
};

treefmt = {
enable = true;
package = config.treefmt.build.wrapper;
pass_filenames = false;
verbose = true;
};
};
};
Expand Down
Loading