diff --git a/README.md b/README.md index 4266d53..677afdd 100644 --- a/README.md +++ b/README.md @@ -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. @@ -136,6 +136,12 @@ xxx xxx +## This pull request is a + +- [ ] Patch change +- [ ] Minor change +- [ ] Major change + ## Screenshots (if appropriate) xxx @@ -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 @@ -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 }} ``` diff --git a/dist/index.js b/dist/index.js index 25e3a53..9987aa3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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 { @@ -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; } @@ -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. @@ -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 @@ -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) { @@ -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. @@ -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", @@ -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 { @@ -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 diff --git a/src/index.ts b/src/index.ts index bb4e3ef..4613e12 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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" diff --git a/src/post-release.ts b/src/post-release.ts index 9039e51..02d2178 100644 --- a/src/post-release.ts +++ b/src/post-release.ts @@ -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"; @@ -13,7 +14,17 @@ async function executeOnRelease(): Promise { }; } - 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", @@ -24,17 +35,12 @@ async function executeOnRelease(): Promise { * 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 {