From fbeabf8863b554e5f49deb2442dc2c85c7a13285 Mon Sep 17 00:00:00 2001 From: Miles Yucht Date: Thu, 4 Jan 2024 10:24:36 +0100 Subject: [PATCH 1/5] Fix diff-schema workflow --- .github/workflows/schema.yml | 31 ++++++++++++++++++++++--------- scripts/diff-schema.sh | 9 +++++---- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/.github/workflows/schema.yml b/.github/workflows/schema.yml index 40cb42e65d..01b5b26134 100644 --- a/.github/workflows/schema.yml +++ b/.github/workflows/schema.yml @@ -7,12 +7,12 @@ on: workflow_dispatch: inputs: base: - description: 'Base ref' - default: 'master' + description: "Base ref" + default: "master" required: true head: - description: 'Head ref' - default: 'master' + description: "Head ref" + default: "master" required: true jobs: @@ -21,26 +21,39 @@ jobs: steps: - if: github.event_name == 'pull_request' - name: Checkout + name: Checkout PR base commit + uses: actions/checkout@v4 + with: + ref: ${{ github.base_ref }} + - if: github.event_name == 'pull_request' + name: Checkout PR merge commit uses: actions/checkout@v4 - if: github.event_name == 'workflow_dispatch' - name: Checkout + name: Checkout base commit uses: actions/checkout@v4 with: ref: ${{ github.event.inputs.base }} + - if: github.event_name == 'workflow_dispatch' + name: Checkout head commit + uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.head }} - - name: 'Setup Go' + - name: "Setup Go" uses: actions/setup-go@v4 with: go-version: 1.21.x - - name: 'Setup Terraform' + - name: "Setup Terraform" uses: hashicorp/setup-terraform@v2 with: terraform_wrapper: false - - name: 'Install jd' + - name: "Install jd" run: go install github.com/josephburnett/jd@latest - run: make diff-schema + env: + BASE_COMMIT: ${{ github.event_name == 'pull_request' && github.base_ref || github.event.inputs.base }} + HEAD_COMMIT: ${{ github.event_name == 'pull_request' && github.head_ref || github.event.inputs.head }} diff --git a/scripts/diff-schema.sh b/scripts/diff-schema.sh index bf1e8b9ebb..597228722d 100644 --- a/scripts/diff-schema.sh +++ b/scripts/diff-schema.sh @@ -2,7 +2,8 @@ source scripts/libschema.sh -BASE_BRANCH="master" +BASE=${BASE_COMMIT:-"master"} +HEAD=${HEAD_COMMIT:-"HEAD"} checkout_branch() { local branch=$1 @@ -15,11 +16,11 @@ if [ -n "$(git status --porcelain)" ]; then exit 1 fi -CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) +CURRENT_BRANCH=$(git rev-parse --abbrev-ref $HEAD) NEW_SCHEMA=$(generate_schema) -checkout_branch $BASE_BRANCH +checkout_branch $BASE CURRENT_SCHEMA=$(generate_schema) -checkout_branch $CURRENT_BRANCH +checkout_branch $HEAD set +e jd -color "$CURRENT_SCHEMA" "$NEW_SCHEMA" From f6d113a3e34c36fd058df410130bbbe119435409 Mon Sep 17 00:00:00 2001 From: Miles Yucht Date: Thu, 4 Jan 2024 10:25:56 +0100 Subject: [PATCH 2/5] fix --- scripts/diff-schema.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/diff-schema.sh b/scripts/diff-schema.sh index 597228722d..cc03e7f462 100644 --- a/scripts/diff-schema.sh +++ b/scripts/diff-schema.sh @@ -3,7 +3,8 @@ source scripts/libschema.sh BASE=${BASE_COMMIT:-"master"} -HEAD=${HEAD_COMMIT:-"HEAD"} +CURRENT_BRANCH=$(git rev-parse --abbrev-ref $HEAD) +HEAD=${HEAD_COMMIT:-$CURRENT_BRANCH} checkout_branch() { local branch=$1 @@ -16,7 +17,6 @@ if [ -n "$(git status --porcelain)" ]; then exit 1 fi -CURRENT_BRANCH=$(git rev-parse --abbrev-ref $HEAD) NEW_SCHEMA=$(generate_schema) checkout_branch $BASE CURRENT_SCHEMA=$(generate_schema) From f1fe06525ed17b0b6ab7a19f28fb7e5bb14e2182 Mon Sep 17 00:00:00 2001 From: Miles Yucht Date: Thu, 4 Jan 2024 10:26:49 +0100 Subject: [PATCH 3/5] set xeo pipefail --- scripts/diff-schema.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/diff-schema.sh b/scripts/diff-schema.sh index cc03e7f462..0bd16e5c90 100644 --- a/scripts/diff-schema.sh +++ b/scripts/diff-schema.sh @@ -1,9 +1,10 @@ #!/usr/bin/env bash +set -eo pipefail source scripts/libschema.sh BASE=${BASE_COMMIT:-"master"} -CURRENT_BRANCH=$(git rev-parse --abbrev-ref $HEAD) +CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) HEAD=${HEAD_COMMIT:-$CURRENT_BRANCH} checkout_branch() { From 09d4ea2e5e365010bead24b1631bb4c58fca3136 Mon Sep 17 00:00:00 2001 From: Miles Yucht Date: Thu, 4 Jan 2024 12:01:15 +0100 Subject: [PATCH 4/5] handle head correctly --- scripts/diff-schema.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/diff-schema.sh b/scripts/diff-schema.sh index 0bd16e5c90..ef6239ecad 100644 --- a/scripts/diff-schema.sh +++ b/scripts/diff-schema.sh @@ -7,10 +7,10 @@ BASE=${BASE_COMMIT:-"master"} CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) HEAD=${HEAD_COMMIT:-$CURRENT_BRANCH} -checkout_branch() { - local branch=$1 - echo "Checking out branch: $branch" - git checkout $branch +checkout() { + local ref=$1 + echo "Checking out ref: $ref" + git checkout $ref } if [ -n "$(git status --porcelain)" ]; then @@ -18,10 +18,11 @@ if [ -n "$(git status --porcelain)" ]; then exit 1 fi +checkout $HEAD NEW_SCHEMA=$(generate_schema) -checkout_branch $BASE +checkout $BASE CURRENT_SCHEMA=$(generate_schema) -checkout_branch $HEAD +checkout $CURRENT_BRANCH set +e jd -color "$CURRENT_SCHEMA" "$NEW_SCHEMA" From 2f02ad51b5b912bde70b99c464f8b96c7f8b4387 Mon Sep 17 00:00:00 2001 From: Miles Yucht Date: Thu, 4 Jan 2024 12:02:39 +0100 Subject: [PATCH 5/5] fix --- .github/workflows/schema.yml | 3 ++- scripts/diff-schema.sh | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/schema.yml b/.github/workflows/schema.yml index 01b5b26134..d92a8bdcfa 100644 --- a/.github/workflows/schema.yml +++ b/.github/workflows/schema.yml @@ -20,6 +20,8 @@ jobs: runs-on: ubuntu-latest steps: + # Check out the base commit first and the head commit second. diff-schema + # uses the current commit as the head commit. - if: github.event_name == 'pull_request' name: Checkout PR base commit uses: actions/checkout@v4 @@ -56,4 +58,3 @@ jobs: - run: make diff-schema env: BASE_COMMIT: ${{ github.event_name == 'pull_request' && github.base_ref || github.event.inputs.base }} - HEAD_COMMIT: ${{ github.event_name == 'pull_request' && github.head_ref || github.event.inputs.head }} diff --git a/scripts/diff-schema.sh b/scripts/diff-schema.sh index ef6239ecad..0daf8ad62e 100644 --- a/scripts/diff-schema.sh +++ b/scripts/diff-schema.sh @@ -5,7 +5,6 @@ source scripts/libschema.sh BASE=${BASE_COMMIT:-"master"} CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) -HEAD=${HEAD_COMMIT:-$CURRENT_BRANCH} checkout() { local ref=$1 @@ -18,7 +17,6 @@ if [ -n "$(git status --porcelain)" ]; then exit 1 fi -checkout $HEAD NEW_SCHEMA=$(generate_schema) checkout $BASE CURRENT_SCHEMA=$(generate_schema)