diff --git a/.github/workflows/schema.yml b/.github/workflows/schema.yml index 40cb42e65d..d92a8bdcfa 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: @@ -20,27 +20,41 @@ 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 + 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 }} diff --git a/scripts/diff-schema.sh b/scripts/diff-schema.sh index bf1e8b9ebb..0daf8ad62e 100644 --- a/scripts/diff-schema.sh +++ b/scripts/diff-schema.sh @@ -1,13 +1,15 @@ #!/usr/bin/env bash +set -eo pipefail source scripts/libschema.sh -BASE_BRANCH="master" +BASE=${BASE_COMMIT:-"master"} +CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) -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 @@ -15,11 +17,10 @@ if [ -n "$(git status --porcelain)" ]; then exit 1 fi -CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) NEW_SCHEMA=$(generate_schema) -checkout_branch $BASE_BRANCH +checkout $BASE CURRENT_SCHEMA=$(generate_schema) -checkout_branch $CURRENT_BRANCH +checkout $CURRENT_BRANCH set +e jd -color "$CURRENT_SCHEMA" "$NEW_SCHEMA"