Skip to content

Commit

Permalink
Merge branch 'main' into vacuum_agg_index
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyFan2002 authored Jan 10, 2025
2 parents add76c1 + dd3651d commit d5e2ab2
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 91 deletions.
205 changes: 151 additions & 54 deletions .github/scripts/bump_version.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,174 @@
module.exports = async ({ github, context, core }) => {
const knownEvents = ["schedule", "workflow_dispatch", "release"];
const knownEvents = ["schedule", "workflow_dispatch"];
if (!knownEvents.includes(context.eventName)) {
core.setFailed(`Triggerd by unknown event: ${context.eventName}`);
return;
}

const { STABLE, TAG } = process.env;
const { TYPE, TAG } = process.env;

// trigger by release event
if (context.ref.startsWith("refs/tags/")) {
let tag = context.ref.replace("refs/tags/", "");
core.setOutput("tag", tag);
core.setOutput("sha", context.sha);
core.info(`Tag event triggered by ${tag}.`);
return;
}
const RE_TAG_STABLE = /^v(\d+)\.(\d+)\.(\d+)$/g;
const RE_TAG_NIGHTLY = /^v(\d+)\.(\d+)\.(\d+)-nightly$/g;
const RE_TAG_PATCH = /^v(\d+)\.(\d+)\.(\d+)-p(\d+)$/g;

switch (TYPE) {
case "":
case "nightly": {
core.setOutput("sha", context.sha);
core.info(`Nightly release triggered by ${TAG} (${context.sha})`);

// trigger by schedule or workflow_dispatch event
if (STABLE == "true") {
if (TAG) {
// trigger stable release by workflow_dispatch with a tag
let result = /v(\d+)\.(\d+)\.(\d+)-nightly/g.exec(TAG);
let previous = null;
const releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
});
for (const release of releases.data) {
const result = RE_TAG_NIGHTLY.exec(release.tag_name);
if (result) {
previous = release.tag_name;
break;
}
}
core.setOutput("previous", previous);
core.info(`Nightly release with previous release: ${previous}`);

if (TAG) {
core.setOutput("tag", TAG);
core.info(`Release create manually with tag ${TAG}`);
return;
}
const result = RE_TAG_NIGHTLY.exec(previous);
if (!result) {
core.setFailed(`The tag ${TAG} to stablize is invalid, ignoring`);
core.setFailed(`The previous tag ${previous} is invalid.`);
return;
}
let major = result[1];
let minor = result[2];
let patch = result[3];
let stableTag = `v${major}.${minor}.${patch}`;
core.setOutput("tag", stableTag);
let ref = await github.rest.git.getRef({
const major = result[1];
const minor = result[2];
const patch = (parseInt(result[3]) + 1).toString();
const nextTag = `v${major}.${minor}.${patch}-nightly`;
core.setOutput("tag", nextTag);
core.info(`Release create new nightly ${nextTag}`);
return;
}

case "stable": {
core.setOutput("sha", context.sha);
if (!TAG) {
core.setFailed("Stable release must be triggered with a nightly tag");
return;
}
core.info(`Stable release triggered by ${TAG} (${context.sha})`);
const result = RE_TAG_NIGHTLY.exec(TAG);
if (!result) {
core.setFailed(`The tag ${TAG} is invalid, ignoring`);
return;
}
const major = result[1];
const minor = result[2];
const patch = result[3];
const nextTag = `v${major}.${minor}.${patch}`;
core.setOutput("tag", nextTag);
core.info(`Stable release ${nextTag} from ${TAG}`);

let previous = null;
let page = 1;
while (true) {
const releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
page,
});
if (releases.data.length === 0) {
break;
}
page++;
for (const release of releases.data) {
const ret = RE_TAG_STABLE.exec(release.tag_name);
if (ret) {
previous = release.tag_name;
break;
}
}
}
if (!previous) {
core.setFailed(`No previous stable release found, ignoring`);
return;
}
core.setOutput("previous", previous);
core.info(`Stable release with previous release: ${previous}`);
}

case "patch": {
if (!TAG) {
core.setFailed("Patch release must be triggered with a stable tag");
return;
}
core.info(`Patch release triggered by ${TAG}`);
const result = RE_TAG_STABLE.exec(TAG);
if (!result) {
core.setFailed(`The tag ${TAG} is invalid, ignoring`);
return;
}

const branch = await github.rest.repos.getBranch({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${TAG}`,
branch: `backport/${TAG}`,
});
core.setOutput("sha", ref.data.object.sha);
core.setOutput("sha", branch.data.commit.sha);
core.info(
`Stable release ${stableTag} from ${TAG} (${ref.data.object.sha})`
`Patch release triggered by ${TAG} (${branch.data.commit.sha})`
);
} else {
core.setFailed("Stable release must be triggered with a nightly tag");
}
} else {
core.setOutput("sha", context.sha);
if (TAG) {
core.setOutput("tag", TAG);
core.info(`Release create manually with tag ${TAG} (${context.sha})`);
} else {
let releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 10,
});
let tag = releases.data.filter(
(r) => r.tag_name.startsWith("v") && r.tag_name.endsWith("-nightly")
)[0];
if (!tag) {
core.setFailed(`No previous nightly release found, ignoring`);
return;

let pv = 1;
let previous = null;
let page = 1;
while (true) {
const releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
page,
});
if (releases.data.length === 0) {
break;
}
page++;
for (const release of releases.data) {
if (!release.tag_name.startsWith(TAG)) {
continue;
}
if (release.tag_name === TAG) {
previous = release.tag_name;
break;
}
const ret = RE_TAG_PATCH.exec(release.tag_name);
if (!ret) {
core.warning(`Ignore previous release ${release.tag_name}`);
continue;
}
pv = parseInt(result[4]) + 1;
previous = release.tag_name;
}
}
let lastTag = tag.tag_name;
let result = /v(\d+)\.(\d+)\.(\d+)/g.exec(lastTag);
if (!result) {
core.setFailed(`The previous tag ${lastTag} is invalid, ignoring`);
if (!previous) {
core.setFailed(`No previous stable release found, ignoring`);
return;
}
let major = result[1];
let minor = result[2];
let patch = (parseInt(result[3]) + 1).toString();
let nextTag = `v${major}.${minor}.${patch}-nightly`;
core.setOutput("previous", previous);
core.info(`Patch release with previous release: ${previous}`);

const major = result[1];
const minor = result[2];
const patch = result[3];
const nextTag = `v${major}.${minor}.${patch}-p${pv}`;
core.setOutput("tag", nextTag);
core.info(`Nightly release ${nextTag} from ${lastTag} (${context.sha})`);
core.info(`Patch release ${nextTag} from ${TAG}`);
return;
}

default: {
core.setFailed(`Unknown release type: ${TYPE}`);
return;
}
}
};
74 changes: 39 additions & 35 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@ on:
workflow_dispatch:
inputs:
tag:
description: The tags to be released
description: |
The tags to be released.
Nightly release dose not require a tag.
Stable release requires a nightly version (v1.0.0-nightly).
Patch release requires a stable version (v1.0.0).
required: false
type: string
stable:
description: Make a stable release
required: false
type: boolean
release:
types:
- published
type:
description: Release type, default to nightly
required: true
type: choice
default: nightly
options:
- nightly
- stable
- patch

permissions:
id-token: write
Expand Down Expand Up @@ -43,33 +49,33 @@ jobs:
id: bump
uses: actions/github-script@v7
env:
STABLE: "${{ inputs.stable }}"
TYPE: "${{ inputs.type }}"
TAG: "${{ inputs.tag }}"
with:
script: |
const script = require('./.github/scripts/bump_version.js')
await script({ github, context, core })
- name: Create release
if: github.event_name == 'workflow_dispatch'
env:
# we need workflow:write permission to create release if there were any workflow changes
# which is not possible for github actions token
GH_TOKEN: ${{ secrets.DATABEND_BOT_TOKEN }}
run: |
echo "Creating release ${{ steps.bump.outputs.tag }} from ${{ steps.bump.outputs.sha }}"
if [[ "${{ inputs.stable }}" == "true" ]]; then
previous=$(gh release list --limit 10 --exclude-pre-releases | grep -v p | head -n 1 | cut -f 1)
echo "Stable release with previous release: $previous"
gh release create ${{ steps.bump.outputs.tag }} --target ${{ steps.bump.outputs.sha }} --generate-notes --notes-start-tag $previous --latest --draft
else
previous=$(gh release list --limit 10 | grep nightly | head -n 1 | cut -f 1)
echo "Nightly release with previous release: $previous"
gh release create ${{ steps.bump.outputs.tag }} --target ${{ steps.bump.outputs.sha }} --generate-notes --notes-start-tag $previous --prerelease --draft
fi
case "${{ inputs.type }}" in
nightly)
gh release create ${{ steps.bump.outputs.tag }} --target ${{ steps.bump.outputs.sha }} --generate-notes --notes-start-tag ${{ steps.bump.outputs.previous }} --prerelease --draft
;;
stable)
gh release create ${{ steps.bump.outputs.tag }} --target ${{ steps.bump.outputs.sha }} --generate-notes --notes-start-tag ${{ steps.bump.outputs.previous }} --latest --draft
;;
patch)
gh release create ${{ steps.bump.outputs.tag }} --target ${{ steps.bump.outputs.sha }} --generate-notes --notes-start-tag ${{ steps.bump.outputs.previous }} --prerelease --draft
;;
esac
changelog:
runs-on: ubuntu-latest
if: inputs.stable
if: inputs.type == 'stable'
needs: create_release
steps:
- name: Checkout Docs
Expand Down Expand Up @@ -281,16 +287,15 @@ jobs:
REPO_DOCKERHUB: ${{ steps.login.outputs.dockerhub_repo }}
REPO_ECR: ${{ steps.login.outputs.ecr_repo }}
VERSION: ${{ needs.create_release.outputs.version }}
STABLE: ${{ inputs.stable }}
TYPE: ${{ inputs.type }}
with:
script: |
const version = process.env.VERSION;
const repos = [process.env.REPO_DOCKERHUB, process.env.REPO_ECR];
const stable = process.env.STABLE;
const { VERSION, TYPE, REPO_DOCKERHUB, REPO_ECR } = process.env;
const repos = [REPO_DOCKERHUB, REPO_ECR];
let tags = [];
for (const repo of repos) {
tags.push(`${repo}:${version}`);
if (stable === 'true') {
tags.push(`${repo}:${VERSION}`);
if (TYPE === 'stable') {
tags.push(`${repo}:latest`);
} else {
tags.push(`${repo}:nightly`);
Expand Down Expand Up @@ -362,16 +367,15 @@ jobs:
REPO_DOCKERHUB: ${{ steps.login.outputs.dockerhub_repo }}
REPO_ECR: ${{ steps.login.outputs.ecr_repo }}
VERSION: ${{ needs.create_release.outputs.version }}
STABLE: ${{ inputs.stable }}
TYPE: ${{ inputs.type }}
with:
script: |
const version = process.env.VERSION;
const repos = [process.env.REPO_DOCKERHUB, process.env.REPO_ECR];
const stable = process.env.STABLE;
const { VERSION, TYPE, REPO_DOCKERHUB, REPO_ECR } = process.env;
const repos = [REPO_DOCKERHUB, REPO_ECR];
let tags = [];
for (const repo of repos) {
tags.push(`${repo}:${version}`);
if (stable === 'true') {
tags.push(`${repo}:${VERSION}`);
if (TYPE === 'stable') {
tags.push(`${repo}:latest`);
} else {
tags.push(`${repo}:nightly`);
Expand Down Expand Up @@ -410,7 +414,7 @@ jobs:
packager: ${{ matrix.packager }}

# bindings_python:
# if: inputs.stable
# if: inputs.type == 'stable'
# needs: create_release
# uses: ./.github/workflows/bindings.python.yml
# secrets: inherit
Expand Down Expand Up @@ -450,7 +454,7 @@ jobs:
deb:
runs-on: ubuntu-latest
if: inputs.stable
if: inputs.type == 'stable'
needs: [create_release, distribution]
steps:
- uses: actions/checkout@v4
Expand Down
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d5e2ab2

Please sign in to comment.