mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-10 15:02:56 +00:00
## Problem When we release our components, we perform builds in the release PR, then test the components, then merge the PR, and then build everything *again*, run tests *again*, and only then start deployments. To speed things up, we want to perform builds and run tests in the PR, and start deployments using the existing artifacts from the release PR. To make that possible, we need to have both CI pipelines running on the same commit hash, which requires fast forwarding release. That only works, if we have a commit in the PR that has the current release branch state as an ancestor. ## Summary of changes - Changes to release PR creation: - Remove templates and automatic bodies for release PRs. The previous template wasn't used anymore, and the automatic body we created in the pipeline didn't contain any useful content anymore after the changees here. - Make it possible to select the source branch. For releases that aren't cut from `main`, like https://github.com/neondatabase/neon/pull/11051, we need a way to trigger the new flow from a different branch. - Determine `release-branch` automatically from the component name instead of passing that as well. - Changes to the merge queue job: - Rename `get-changed-files` to `meta` in preparation of additional data being fetched as part of that job - Fail the merge queue if we're trying to merge into a branch other than main - this is to prevent non-fast-forward merges. - Label PRs to branches other than main as `fast-forward`, to trigger the fast-forward job - Add a fast-forward job that can be triggered with the `fast-forward` label that performs a fast-forward merge. This only happens if the PR has `mergeable_state == clean`, so CI having passed. - Build and Test on releases now skips building images, skips testing images and skips triggering e2e tests. We add new tags to the images from the release PR to tag them as release images, and we push them to the prod registries.
130 lines
6.0 KiB
YAML
130 lines
6.0 KiB
YAML
name: Generate run metadata
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
github-event-name:
|
|
type: string
|
|
required: true
|
|
outputs:
|
|
build-tag:
|
|
description: "Tag for the current workflow run"
|
|
value: ${{ jobs.tags.outputs.build-tag }}
|
|
previous-storage-release:
|
|
description: "Tag of the last storage release"
|
|
value: ${{ jobs.tags.outputs.storage }}
|
|
previous-proxy-release:
|
|
description: "Tag of the last proxy release"
|
|
value: ${{ jobs.tags.outputs.proxy }}
|
|
previous-compute-release:
|
|
description: "Tag of the last compute release"
|
|
value: ${{ jobs.tags.outputs.compute }}
|
|
run-kind:
|
|
description: "The kind of run we're currently in. Will be one of `push-main`, `storage-release`, `compute-release`, `proxy-release`, `storage-rc-pr`, `compute-rc-pr`, `proxy-rc-pr`, `pr`, or `workflow-dispatch`"
|
|
value: ${{ jobs.tags.outputs.run-kind }}
|
|
release-pr-run-id:
|
|
description: "Only available if `run-kind in [storage-release, proxy-release, compute-release]`. Contains the run ID of the `Build and Test` workflow, assuming one with the current commit can be found."
|
|
value: ${{ jobs.tags.outputs.release-pr-run-id }}
|
|
|
|
permissions: {}
|
|
|
|
defaults:
|
|
run:
|
|
shell: bash -euo pipefail {0}
|
|
|
|
jobs:
|
|
tags:
|
|
runs-on: ubuntu-22.04
|
|
outputs:
|
|
build-tag: ${{ steps.build-tag.outputs.tag }}
|
|
compute: ${{ steps.previous-releases.outputs.compute }}
|
|
proxy: ${{ steps.previous-releases.outputs.proxy }}
|
|
storage: ${{ steps.previous-releases.outputs.storage }}
|
|
run-kind: ${{ steps.run-kind.outputs.run-kind }}
|
|
release-pr-run-id: ${{ steps.release-pr-run-id.outputs.release-pr-run-id }}
|
|
permissions:
|
|
contents: read
|
|
steps:
|
|
# Need `fetch-depth: 0` to count the number of commits in the branch
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Get run kind
|
|
id: run-kind
|
|
env:
|
|
RUN_KIND: >-
|
|
${{
|
|
false
|
|
|| (inputs.github-event-name == 'push' && github.ref_name == 'main') && 'push-main'
|
|
|| (inputs.github-event-name == 'push' && github.ref_name == 'release') && 'storage-release'
|
|
|| (inputs.github-event-name == 'push' && github.ref_name == 'release-compute') && 'compute-release'
|
|
|| (inputs.github-event-name == 'push' && github.ref_name == 'release-proxy') && 'proxy-release'
|
|
|| (inputs.github-event-name == 'pull_request' && github.base_ref == 'release') && 'storage-rc-pr'
|
|
|| (inputs.github-event-name == 'pull_request' && github.base_ref == 'release-compute') && 'compute-rc-pr'
|
|
|| (inputs.github-event-name == 'pull_request' && github.base_ref == 'release-proxy') && 'proxy-rc-pr'
|
|
|| (inputs.github-event-name == 'pull_request') && 'pr'
|
|
|| (inputs.github-event-name == 'workflow_dispatch') && 'workflow-dispatch'
|
|
|| 'unknown'
|
|
}}
|
|
run: |
|
|
echo "run-kind=$RUN_KIND" | tee -a $GITHUB_OUTPUT
|
|
|
|
- name: Get build tag
|
|
id: build-tag
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
CURRENT_BRANCH: ${{ github.head_ref || github.ref_name }}
|
|
CURRENT_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
|
|
RUN_KIND: ${{ steps.run-kind.outputs.run-kind }}
|
|
run: |
|
|
case $RUN_KIND in
|
|
push-main)
|
|
echo "tag=$(git rev-list --count HEAD)" | tee -a $GITHUB_OUTPUT
|
|
;;
|
|
storage-release)
|
|
echo "tag=release-$(git rev-list --count HEAD)" | tee -a $GITHUB_OUTPUT
|
|
;;
|
|
proxy-release)
|
|
echo "tag=release-proxy-$(git rev-list --count HEAD)" | tee -a $GITHUB_OUTPUT
|
|
;;
|
|
compute-release)
|
|
echo "tag=release-compute-$(git rev-list --count HEAD)" | tee -a $GITHUB_OUTPUT
|
|
;;
|
|
pr|storage-rc-pr|compute-rc-pr|proxy-rc-pr)
|
|
BUILD_AND_TEST_RUN_ID=$(gh api --paginate \
|
|
-H "Accept: application/vnd.github+json" \
|
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
|
"/repos/${GITHUB_REPOSITORY}/actions/runs?head_sha=${CURRENT_SHA}&branch=${CURRENT_BRANCH}" \
|
|
| jq '[.workflow_runs[] | select(.name == "Build and Test")][0].id // ("Error: No matching workflow run found." | halt_error(1))')
|
|
echo "tag=$BUILD_AND_TEST_RUN_ID" | tee -a $GITHUB_OUTPUT
|
|
;;
|
|
workflow-dispatch)
|
|
echo "tag=$GITHUB_RUN_ID" | tee -a $GITHUB_OUTPUT
|
|
;;
|
|
*)
|
|
echo "Unexpected RUN_KIND ('${RUN_KIND}'), failing to assign build-tag!"
|
|
exit 1
|
|
esac
|
|
|
|
- name: Get the previous release-tags
|
|
id: previous-releases
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
gh api --paginate \
|
|
-H "Accept: application/vnd.github+json" \
|
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
|
"/repos/${GITHUB_REPOSITORY}/releases" \
|
|
| jq -f .github/scripts/previous-releases.jq -r \
|
|
| tee -a "${GITHUB_OUTPUT}"
|
|
|
|
- name: Get the release PR run ID
|
|
id: release-pr-run-id
|
|
if: ${{ contains(fromJson('["storage-release", "compute-release", "proxy-release"]'), steps.run-kind.outputs.run-kind) }}
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
CURRENT_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
|
|
run: |
|
|
RELEASE_PR_RUN_ID=$(gh api "/repos/${GITHUB_REPOSITORY}/actions/runs?head_sha=$CURRENT_SHA" | jq '[.workflow_runs[] | select(.name == "Build and Test") | select(.head_branch | test("^rc/release(-(proxy)|(compute))?/[0-9]{4}-[0-9]{2}-[0-9]{2}$"; "s"))] | first | .id // "Faied to find Build and Test run from RC PR!" | halt_error(1)')
|
|
echo "release-pr-run-id=$RELEASE_PR_RUN_ID" | tee -a $GITHUB_OUTPUT
|