Skip to content

Add release-latest option #6213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
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
39 changes: 31 additions & 8 deletions .github/workflows/release-to-branches-in-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
branches:
- master
- main
- letz-release-now
types:
- closed

Expand All @@ -16,6 +17,9 @@ jobs:
# Only run if the PR was actually merged
if: ${{ github.event.pull_request.merged == true }}

env:
TYK_LATEST_RELEASE_BRANCH: "release-99" # Example value for testing

steps:
- name: Add a comment to the merged PR (only if labeler is in the org)
uses: actions/github-script@v7
Expand All @@ -24,11 +28,13 @@ jobs:
script: |
// 1. The label format: e.g., "release-1", "release-1.0"
const labelRegex = /^release-[0-9]+(\.[0-9]+)?$/;
const latestReleaseLabel = "latest-release";

// 2. Get PR info
const pullRequestNumber = context.payload.pull_request.number;
const labelsOnPR = context.payload.pull_request.labels || [];
console.log("Labels on the Pull Request:", labelsOnPR.map(label => label.name));

// 3. Get all timeline events to see who labeled the PR
const { data: prEvents } = await github.rest.issues.listEvents({
owner: context.repo.owner,
Expand Down Expand Up @@ -57,7 +63,8 @@ jobs:
// 6. For each label on the PR, check if it matches "release-.."
// If yes, we see who labeled it last and check their membership
for (const label of labelsOnPR) {
if (labelRegex.test(label.name)) {
// Check if it's a regular release label or the special "latest-release" label
if (labelRegex.test(label.name) || label.name === releaseNowLabel) {
const userWhoAddedLabel = labelToLastLabeler[label.name];

// If there's no recorded user (edge case), skip
Expand Down Expand Up @@ -88,13 +95,29 @@ jobs:

// 8. Comment only if user is in the org
if (isMember) {
console.log(`Creating comment for label '${label.name}' on PR #${pullRequestNumber} by user '${userWhoAddedLabel}'.`);
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pullRequestNumber,
body: `/release to ${label.name}`
});
let commentBody;

// Handle special "latest-release" case
if (label.name === latestReleaseLabel) {
// Get the latest release branch from environment variable
const latestReleaseBranch = process.env.TYK_LATEST_RELEASE_BRANCH;
if (!latestReleaseBranch) {
console.log("TYK_LATEST_RELEASE_BRANCH environment variable is not set");
continue;
}
commentBody = `/release to ${latestReleaseBranch}`;
} else {
// Regular release label
commentBody = `/release to ${label.name}`;
}

console.log(`Creating comment for label '$commentBody' on PR #${pullRequestNumber} by user '${userWhoAddedLabel}'.`);
# await github.rest.issues.createComment({
# owner: context.repo.owner,
# repo: context.repo.repo,
# issue_number: pullRequestNumber,
# body: commentBody
# });
}else{
console.log(`No comment created for label '${label.name}' on PR #${pullRequestNumber} because the user '${userWhoAddedLabel}' is not a member of the organization 'TykTechnologies'.`);
}
Expand Down
Loading