Skip to content

Commit

Permalink
Update the release notes generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
cvetty committed Dec 15, 2024
1 parent 867aeb0 commit f279f5b
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 105 deletions.
2 changes: 1 addition & 1 deletion .github/actions/draft-release/script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = async ({ github, context, inputs }) => {
const tagName = `unreleased[${inputs.branchName}]`;
const tagName = `${inputs.branchName}-unreleased`;
const releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/pre-release/script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = async ({ github, context, inputs }) => {
const draftTagName = `unreleased[${inputs.branchName}]`;
const draftTagName = `${inputs.branchName}-unreleased`;

const releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
name: "Release"
description: "Release the pre-release release"
name: "Release cleanup"
description: "Beta versions cleanup"

inputs:
release_id:
description: "The id of the target release"
required: true
tag_name:
description: "The release version tag"
required: true
Expand All @@ -24,7 +21,6 @@ runs:
github,
context,
inputs: {
releaseId: '${{ inputs.release_id }}',
tagName: '${{ inputs.tag_name }}',
}
})
Expand Down
48 changes: 48 additions & 0 deletions .github/actions/release-cleanup/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module.exports = async ({ github, context, inputs }) => {
const majorVersion = inputs.tagName.split(".")[0];

// Cleanup beta releases
console.log("Cleaning up beta releases...");
const { data: releases } = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
});

for (const release of releases) {
if (
!release.tag_name.startsWith(`${majorVersion}.`) ||
!release.tag_name.includes("-beta")
) {
continue;
}

console.log(`Deleting beta release: ${release.tag_name}`);
await github.rest.repos.deleteRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.id,
});
}

// Cleanup beta tags
console.log("Cleaning up beta tags...");
const { data: tags } = await github.rest.repos.listTags({
owner: context.repo.owner,
repo: context.repo.repo,
});
for (const tag of tags) {
if (
!tag.name.startsWith(`${majorVersion}.`) ||
!tag.name.includes("-beta")
) {
continue;
}

console.log(`Deleting beta tag: ${tag.name}`);
await github.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${tag.name}`,
});
}
};
59 changes: 0 additions & 59 deletions .github/actions/release/script.js

This file was deleted.

2 changes: 0 additions & 2 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# .github/release.yml
# Contains configure for auto generated release notes
changelog:
exclude:
labels:
Expand Down
61 changes: 25 additions & 36 deletions .github/workflows/cd_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
runs-on: "ubuntu-22.04"
outputs:
version_branch: ${{ steps.get-version-details.outputs.major_version}}.x
release_version: ${{ steps.get-clean-version.outputs.version }}
steps:
- name: Get Github token
id: get-github-token
Expand All @@ -35,69 +34,57 @@ jobs:
application_id: ${{ vars.GH_MTR_PACKAGE_VERSIONS_APP_ID }}
application_private_key: ${{ secrets.GH_MTR_PACKAGE_VERSIONS_APP_SECRET }}

- name: Get release title and tag
- name: Get release version details
id: get-version-details
run: |
echo "release_title=${{ github.event.release.name }}" >> $GITHUB_OUTPUT
echo "release_tag=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT
# Extract major version (handles v1.2.3-beta.0 or 1.2.3-beta.0)
MAJOR_VERSION=$(echo "${{ github.event.release.tag_name }}" | sed 's/^v\{0,1\}\([0-9]\+\)[^0-9].*/\1/')
echo "major_version=$MAJOR_VERSION" >> $GITHUB_OUTPUT
- name: Checkout code
- name: Checkout the repository
uses: actions/checkout@v4
with:
ref: ${{ steps.get-version-details.outputs.major_version}}.x
token: ${{ steps.get-github-token.outputs.token }}

- name: Check release title format
- name: Verify the release title
env:
RELEASE_TITLE: ${{ steps.get-version-details.outputs.release_title }}
RELEASE_TITLE: ${{ github.event.release.name }}
run: |
if [[ -z "$RELEASE_TITLE" ]]; then
echo "Release title cannot be empty"
exit 1
fi
TITLE_VERSION_REGEX="^v[0-9]+\.[0-9]+\.[0-9]+(-alpha|-beta)?$"
TITLE_VERSION_REGEX="^v[0-9]+\.[0-9]+\.[0-9]+$"
if [[ ! $RELEASE_TITLE =~ $TITLE_VERSION_REGEX ]]; then
echo "Invalid release title format: $RELEASE_TITLE"
exit 1
else
echo "Release title $RELEASE_TITLE is valid"
fi
- name: Get the clean version
id: get-clean-version
env:
TAG_NAME: ${{ steps.get-version-details.outputs.tag_name }}
run: |
VERSION=$(echo "$TAG_NAME" | sed 's/^v//' | cut -d'-' -f1)
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Set up Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Update package.json version
env:
CLEAN_VERSION: ${{ steps.get-clean-version.outputs.version }}
VERSION: ${{ github.event.release.tag_name }}
run: |
npm version $CLEAN_VERSION
npm version $VERSION
- name: Commit version bump in different branch
id: create-release-branch
- name: Commit the version bump update
env:
CLEAN_VERSION: ${{ steps.get-clean-version.outputs.version }}
VERSION: ${{ github.event.release.tag_name }}
GITHUB_TOKEN: ${{ steps.get_workflow_token.outputs.token }}
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git add .
git commit -am "Bump version to $CLEAN_VERSION"
git commit -am "[GHA] Update package version to $VERSION"
git push origin HEAD:$CLEAN_VERSION
release:
Expand Down Expand Up @@ -153,18 +140,22 @@ jobs:
- name: Delete existing release asset
uses: actions/github-script@v6
env:
ASSET_ID: ${{ steps.download-production-build.outputs.result }}
with:
script: |
const assetId = ${{ steps.download-production-build.outputs.result }}
const {ASSET_ID} = process.env
await github.rest.repos.deleteReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
asset_id: assetId
asset_id: ASSET_ID
});
- name: Upload an Asset in GitHub Release
uses: actions/github-script@v6
env:
RELEASE_ID: ${{ github.event.release.id }}
with:
script: |
const {RELEASE_ID} = process.env
Expand All @@ -177,16 +168,6 @@ jobs:
release_id: ${{ env.RELEASE_ID }},
data: await fs.readFile('./krait-ui/distribution-package.zip')
});
env:
RELEASE_ID: ${{ github.event.release.id }}

- name: Set pre-release tag
id: update-release
uses: ./.github/actions/release
with:
release_id: ${{ github.event.release.id }}
tag_name: ${{ needs.bump_version.outputs.release_version }}
node_auth_token: ${{ secrets.NPM_AUTH_TOKEN }}
- name: Unzip the distribution build
working-directory: krait-ui
Expand All @@ -197,3 +178,11 @@ jobs:
# run: npm publish --access public
# env:
# NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

- name: Release cleanup
id: update-release
uses: ./.github/actions/release-cleanup
with:
release_id: ${{ github.event.release.id }}
tag_name: ${{ needs.bump_version.outputs.release_version }}
node_auth_token: ${{ secrets.NPM_AUTH_TOKEN }}

0 comments on commit f279f5b

Please sign in to comment.