Skip to content

Commit

Permalink
ci: add issues commenting after release (#10107) [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
ilhan007 authored Oct 29, 2024
1 parent 8d971b8 commit 16c6f42
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 46 deletions.
85 changes: 48 additions & 37 deletions .github/actions/commentOnFixedIssues.mjs
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
import { promises as fs } from 'node:fs';
import { success as issueCommenter } from '@semantic-release/github';

const getRelease = async (github, version) => {
const releaseInfo = await github.request('GET /repos/{owner}/{repo}/releases/tags/{tag}', {
owner: context.repo.owner,
repo: context.repo.repo,
tag: `v${version}`
});
const release = releaseInfo.data;
release.url = release.html_url;
const getReleaseCommits = (releaseBody) => {
const commits = new Set();

return release;
};

const getReleaseCommits = (release) => {
const commits = [];

let result;
do {
result = /commit\/(?<sha>\w{40})/gm.exec(release.body);
if (result?.groups?.sha) {
commits.push({ hash: result.groups.sha });
const shaRegex = /commit\/(?<sha>\w{40})/g;
for (const match of releaseBody.matchAll(shaRegex)) {
if (match.groups?.sha) {
commits.add({ hash: match.groups.sha });
}
} while (result);
}

return commits;
// Converting Set back to an array to get unique commits as array
return Array.from(commits);
};

const getOctokitShim = (github) => {
Expand All @@ -37,23 +25,46 @@ const getOctokitShim = (github) => {

/**
* Publishes comments to issues that are fixed and released.
* @param options.github
* @param options {object}
* @param options.github {import("@octokit/rest/dist-types/index.d.ts").Octokit}
* @param options.context
* @returns {Promise<void>}
*/
export default async function run({ github, context }) {
const lerna = await fs.readFile(new URL('../../lerna.json', import.meta.url), 'utf8');
const { version } = JSON.parse(lerna);
const release = await getRelease(version);
const commits = getReleaseCommits(release);
const Octokit = getOctokitShim(github);

await issueCommenter({}, {
options: { repositoryUrl: `https://github.com/${context.repo.owner}/${context.repo.repo}`},
commits,
nextRelease: { version: `v${version}` },
releases: [release],
logger: console,
env: process.env
}, { Octokit });
const lerna = await fs.readFile(new URL('../../lerna.json', import.meta.url), 'utf8');
const { version } = JSON.parse(lerna);

const { owner, repo } = context.repo;
const releaseInfo = await github.request('GET /repos/{owner}/{repo}/releases/tags/{tag}', {
owner,
repo,
tag: `v${version}`
});
const release = releaseInfo.data;
release.url = release.html_url;


const commits = await getReleaseCommits(release.body);


try {
const semanticReleaseContext = {
options: {
repositoryUrl: `https://github.com/${owner}/${repo}`
},
commits,
nextRelease: { version: `v${version}` },
releases: [release],
logger: console,
env: process.env
};
const Octokit = getOctokitShim(github);

console.log('Commits:', commits.toString());
console.log('semanticReleaseContext:', semanticReleaseContext);

await issueCommenter({}, semanticReleaseContext, { Octokit });

} catch (error) {
console.error('Error in posting comment:', error);
}
}
19 changes: 11 additions & 8 deletions .github/workflows/issues-handling.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on: workflow_dispatch
jobs:
test-issue-comment:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
issues: write
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -18,15 +22,14 @@ jobs:
- name: Install
run: yarn --frozen-lockfile

- name: Add release comments to issues and PRs
uses: actions/github-script@v6
- name: Publish Release Comments
uses: actions/github-script@v7
env:
NODE_OPTIONS: '--max-old-space-size=12096'
GH_TOKEN: ${{ secrets.UI5_WEBCOMP_BOT_GH_TOKEN }}
with:
github-token: ${{ secrets.UI5_WEBCOMP_BOT_GH_TOKEN }}
script: |
const { readFileSync } = require('fs');
const { URL } = require('url');
const { version } = require('./lerna.json');
console.log('Create issue comments for lerna version: ', version);
const script = require('./.github/actions/createIssueComments.cjs');
аwait script({ github: github.rest, context, core, version })
const commentOnFixedIssues = (await import('${{ github.workspace }}/.github/actions/commentOnFixedIssues.mjs')).default;
await commentOnFixedIssues({ github , context });
7 changes: 6 additions & 1 deletion .github/workflows/release-stable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ on:
jobs:
build-and-release:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
issues: write
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -57,10 +61,11 @@ jobs:
- name: Publish Release Comments
uses: actions/github-script@v7
env:
NODE_OPTIONS: '--max-old-space-size=12096'
GH_TOKEN: ${{ secrets.UI5_WEBCOMP_BOT_GH_TOKEN }}
with:
github-token: ${{ secrets.UI5_WEBCOMP_BOT_GH_TOKEN }}
script: |
const commentOnFixedIssues = (await import('${{ github.workspace }}/.github/actions/commentOnFixedIssues.mjs')).default;
await commentOnFixedIssues({ github, context })
await commentOnFixedIssues({ github, context });

0 comments on commit 16c6f42

Please sign in to comment.