Skip to content

Commit

Permalink
Merge pull request #95 from tiktok/chore-gh-release
Browse files Browse the repository at this point in the history
chore: sparo github release
  • Loading branch information
chengcyber authored Oct 23, 2024
2 parents eb13bd4 + 5139dab commit 2e8cd15
Show file tree
Hide file tree
Showing 7 changed files with 548 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/sparo-gh-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Sparo GitHub Release
on:
push:
tags:
- "sparo_v*.*.*"
workflow_dispatch:
inputs:
tag_name:
description: 'Tag name for release'
required: true
default: ''
jobs:
sparo-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
token: ${{ secrets.BOT_ACCESS_TOKEN }}
- name: git config email
run: git config --local user.email [email protected]
- name: git config name
run: git config --local user.name tiktokbot
- name: Extract version from tag
id: extract_version
run: |
# Get the tag name from GITHUB_REF (e.g., refs/tags/sparo_v1.0.0)
TAG_NAME="${GITHUB_REF##*/}"
# Extract the version number (v1.0.0) using regex
VERSION=$(echo "$TAG_NAME" | sed -E 's/^.*_v([0-9]+\.[0-9]+\.[0-9]+.*)$/\1/')
echo "Extracted version: $VERSION"
# Set the output for later use
echo "::set-output name=version::$VERSION"
- name: Generate Release Description
run : node common/scripts/install-run-rush.js generate-release-description --project sparo --version ${{ steps.extract_version.outputs.version }}
- name: Sparo GitHub Release
uses: softprops/action-gh-release@v2
if: ${{ exists('RELEASE/SPARO.md') }}
with:
draft: true
body_path: RELEASE/SPARO.md

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,5 @@ dist-storybook
# Docusaurus build outputs
build
.docusaurus

RELEASE/
53 changes: 53 additions & 0 deletions common/autoinstallers/generate-release-description/generate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const path = require('path');
const { RushConfiguration } = require('@rushstack/rush-sdk');
const { FileSystem } = require('@rushstack/node-core-library');

const rushConfiguration = RushConfiguration.loadFromDefaultLocation();

/** @type (args: { project: string; version: string }) => void */
function generate({project, version}) {

const rushProject = rushConfiguration.getProjectByName(project);

if (!rushProject) {
throw new Error(`Not found project "${project}"`)
}

const { projectFolder } = rushProject;

const changelogJsonFilePath = path.resolve(projectFolder, 'CHANGELOG.json');

if (!FileSystem.exists(changelogJsonFilePath)) {
throw new Error(`Not found changelog.json at ${changelogJsonFilePath}`)
}

const changelogJsonFileContent = FileSystem.readFile(changelogJsonFilePath, 'utf-8');

const changelogJson = JSON.parse(changelogJsonFileContent);

const changeEntry = changelogJson.entries?.find(x => x.version === version);

if (!changeEntry) {
throw new Error(`Not found version "${version}" info in ${changelogJsonFilePath}`)
}

const comments = Object.entries(changeEntry.comments).map(([_, value]) => {
return value.map(x => x.comment);
}).flat();
console.log('commnets', comments);

const content = `### Update
${comments.map(x => `- ${x}`).join('\n')}
`

const releaseFilePath = path.resolve(rushConfiguration.rushJsonFolder, 'RELEASE', `${project.toUpperCase()}.md`)

FileSystem.writeFile(releaseFilePath, content, {
ensureFolderExists: true,
});
}

module.exports = {
generate
}
20 changes: 20 additions & 0 deletions common/autoinstallers/generate-release-description/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const yargs = require('yargs');
const { generate } = require('./generate');

const args = yargs(process.argv.slice(2))
.version(false)
.option('project', {
demandOption: true,
describe: 'A rush project name',
type: 'string'
})
.option('version', {
demandOption: true,
describe: "Version number",
type: 'string'
}).argv;

generate(args);



10 changes: 10 additions & 0 deletions common/autoinstallers/generate-release-description/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "generate-release-description",
"version": "1.0.0",
"private": true,
"dependencies": {
"@rushstack/node-core-library": "^5.9.0",
"@rushstack/rush-sdk": "^5.140.0",
"yargs": "^17.7.2"
}
}
Loading

0 comments on commit 2e8cd15

Please sign in to comment.