Skip to content
Merged
Show file tree
Hide file tree
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
34 changes: 28 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ jobs:
SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}
```

## Example: Prefill release summary
## Example: Prefill release summary and version increment

Using the `pull_numbers_in_release` output and dry run mode, you can prefill the PR body with the release summary depending on your PR template.

Expand All @@ -136,6 +136,12 @@ xxx

xxx

## This pull request is a

- [ ] Patch change
- [ ] Minor change
- [ ] Major change

## Screenshots (if appropriate)

xxx
Expand Down Expand Up @@ -181,11 +187,26 @@ jobs:
match = match?.split('\n').map(s => s.trim()).filter(Boolean).map(
s => s.startsWith('-') || s.startsWith('*') ? s : `* ${s}`
).join('\n');
return `${pr.data.title}\n${match}`;

let type = 0 // patch
if (body.includes("[x] Major")) {
type = 2 // major
} else if (body.includes("[x] Minor")) {
type = 1 // minor
}

return {
summary: `${pr.data.title}\n${match}`,
type,
}
})).then((prs) => prs.filter(Boolean));
const releaseSummary = mergedPrs.join('\n\n');
return resultSummary;
result-encoding: string

const releaseSummary = mergedPrs.map((pr) => pr.summary).join('\n\n');
core.setOutput('release_summary', releaseSummary);

const versionIncrementType = Math.max(...mergedPrs.map((pr) => pr.type));
const versionIncrement = ['patch', 'minor', 'major'][versionIncrementType] || 'patch';
core.setOutput('version_increment', versionIncrement);

- id: release_workflow
name: gitflow-workflow-action release workflows
Expand All @@ -194,7 +215,8 @@ jobs:
develop_branch: "develop"
main_branch: "main"
version: ${{ inputs.version }}
release_summary: ${{ steps.generate_pr_summary.outputs.result }}
release_summary: ${{ steps.generate_pr_summary.outputs.release_summary }}
version_increment: ${{ steps.generate_pr_summary.outputs.version_increment }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
Expand Down
53 changes: 33 additions & 20 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,11 @@ function requireProxy () {
})();
if (proxyVar) {
try {
return new URL(proxyVar);
return new DecodedURL(proxyVar);
}
catch (_a) {
if (!proxyVar.startsWith('http://') && !proxyVar.startsWith('https://'))
return new URL(`http://${proxyVar}`);
return new DecodedURL(`http://${proxyVar}`);
}
}
else {
Expand Down Expand Up @@ -377,6 +377,19 @@ function requireProxy () {
hostLower.startsWith('[::1]') ||
hostLower.startsWith('[0:0:0:0:0:0:0:1]'));
}
class DecodedURL extends URL {
constructor(url, base) {
super(url, base);
this._decodedUsername = decodeURIComponent(super.username);
this._decodedPassword = decodeURIComponent(super.password);
}
get username() {
return this._decodedUsername;
}
get password() {
return this._decodedPassword;
}
}

return proxy;
}
Expand Down Expand Up @@ -24639,7 +24652,7 @@ function requireLib$2 () {
if (this._keepAlive && useProxy) {
agent = this._proxyAgent;
}
if (this._keepAlive && !useProxy) {
if (!useProxy) {
agent = this._agent;
}
// if agent is already assigned use that agent.
Expand Down Expand Up @@ -24671,16 +24684,12 @@ function requireLib$2 () {
agent = tunnelAgent(agentOptions);
this._proxyAgent = agent;
}
// if reusing agent across request and tunneling agent isn't assigned create a new agent
if (this._keepAlive && !agent) {
// if tunneling agent isn't assigned create a new agent
if (!agent) {
const options = { keepAlive: this._keepAlive, maxSockets };
agent = usingSsl ? new https.Agent(options) : new http.Agent(options);
this._agent = agent;
}
// if not using private agent and tunnel agent isn't setup then use global agent
if (!agent) {
agent = usingSsl ? https.globalAgent : http.globalAgent;
}
if (usingSsl && this._ignoreSslError) {
// we don't want to set NODE_TLS_REJECT_UNAUTHORIZED=0 since that will affect request for entire process
// http.RequestOptions doesn't expose a way to modify RequestOptions.agent.options
Expand All @@ -24702,7 +24711,7 @@ function requireLib$2 () {
}
const usingSsl = parsedUrl.protocol === 'https:';
proxyAgent = new undici_1.ProxyAgent(Object.assign({ uri: proxyUrl.href, pipelining: !this._keepAlive ? 0 : 1 }, ((proxyUrl.username || proxyUrl.password) && {
token: `${proxyUrl.username}:${proxyUrl.password}`
token: `Basic ${Buffer.from(`${proxyUrl.username}:${proxyUrl.password}`).toString('base64')}`
})));
this._proxyAgentDispatcher = proxyAgent;
if (usingSsl && this._ignoreSslError) {
Expand Down Expand Up @@ -48584,6 +48593,7 @@ const Config = {
releaseSummary: coreExports.getInput("release_summary") || process.env.RELEASE_SUMMARY || "",
releaseBranchPrefix: "release/",
hotfixBranchPrefix: "hotfix/",
slackOptionsStr: coreExports.getInput("slack") || process.env.SLACK_OPTIONS,
};

const PR_EXPLAIN_MESSAGE = `Merging this pull request will trigger Gitflow release actions. A release would be created and ${Config.mergeBackFromProd ? `${Config.prodBranch}` : "this branch"} would be merged back to ${Config.developBranch} if needed.
Expand Down Expand Up @@ -48705,7 +48715,15 @@ async function executeOnRelease() {
type: "none",
};
}
if (!githubExports.context.payload.pull_request?.merged) {
const pullRequest = githubExports.context.payload
.pull_request;
if (!pullRequest) {
console.log(`on-release: pull request is not defined. Exiting...`);
return {
type: "none",
};
}
if (!pullRequest.merged) {
console.log(`on-release: pull request is not merged. Exiting...`);
return {
type: "none",
Expand All @@ -48715,12 +48733,8 @@ async function executeOnRelease() {
* Precheck
* Check if the pull request has a release label, targeting main branch, and if it was merged
*/
const pullRequestNumber = githubExports.context.payload.pull_request?.number;
const pullRequestNumber = pullRequest.number;
require$$0$4(pullRequestNumber, `github.context.payload.pull_request?.number is not defined`);
const { data: pullRequest } = await octokit.rest.pulls.get({
...Config.repo,
pull_number: pullRequestNumber,
});
const releaseCandidateType = isReleaseCandidate(pullRequest, true);
if (!releaseCandidateType)
return {
Expand Down Expand Up @@ -48760,14 +48774,13 @@ async function executeOnRelease() {
await tryMerge(Config.mergeBackFromProd ? Config.prodBranch : currentBranch, Config.developBranch);
console.log(`on-release: success`);
console.log(`post-release: process release ${release.name}`);
const slackInput = coreExports.getInput("slack") || process.env.SLACK_OPTIONS;
if (slackInput) {
if (Config.slackOptionsStr) {
let slackOpts;
try {
slackOpts = JSON.parse(slackInput);
slackOpts = JSON.parse(Config.slackOptionsStr);
}
catch {
throw new Error(`integration(slack): Could not parse ${slackInput}`);
throw new Error(`integration(slack): Could not parse ${Config.slackOptionsStr}`);
}
/**
* Slack integration
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const start = async () => {
console.log(`gitflow-workflow-action: running with config`, Config);

let res;

if (
github.context.eventName === "pull_request" &&
github.context.payload.action === "closed"
Expand Down
20 changes: 13 additions & 7 deletions src/post-release.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as github from "@actions/github";
import { components } from "@octokit/openapi-types";
import assert from "assert";
import { sendToSlack } from "./integration-slack.js";
import { Config, octokit } from "./shared.js";
Expand All @@ -13,7 +14,17 @@ async function executeOnRelease(): Promise<Result> {
};
}

if (!github.context.payload.pull_request?.merged) {
const pullRequest = github.context.payload
.pull_request as components["schemas"]["pull-request"];

if (!pullRequest) {
console.log(`on-release: pull request is not defined. Exiting...`);
return {
type: "none",
};
}

if (!pullRequest.merged) {
console.log(`on-release: pull request is not merged. Exiting...`);
return {
type: "none",
Expand All @@ -24,17 +35,12 @@ async function executeOnRelease(): Promise<Result> {
* Precheck
* Check if the pull request has a release label, targeting main branch, and if it was merged
*/
const pullRequestNumber = github.context.payload.pull_request?.number;
const pullRequestNumber = pullRequest.number;
assert(
pullRequestNumber,
`github.context.payload.pull_request?.number is not defined`,
);

const { data: pullRequest } = await octokit.rest.pulls.get({
...Config.repo,
pull_number: pullRequestNumber,
});

const releaseCandidateType = isReleaseCandidate(pullRequest, true);
if (!releaseCandidateType)
return {
Expand Down