Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release improvements #3

Merged
merged 5 commits into from
Jan 8, 2025
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
5 changes: 5 additions & 0 deletions .changeset/happy-roses-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'build-uploader': patch
---

Minor log fix
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint": "eslint",
"prettier": "prettier --write .",
"package:changeset": "changeset",
"package:version": "changeset version",
"package:version": "pnpm build && changeset version",
"package:publish": "tsx ./scripts/release.ts"
},
"repository": {
Expand Down
28 changes: 23 additions & 5 deletions scripts/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import path from 'path';

const main = async () => {
try {
// Read the package.json file
const packageJsonPath = path.resolve(process.cwd(), 'package.json');
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
const version = packageJson.version;
Expand All @@ -15,19 +14,38 @@ const main = async () => {

console.log(`Creating tag and release for version: v${version}`);

// Create a Git tag
let lastTag = '';
try {
lastTag = execSync('git describe --tags --abbrev=0').toString().trim();
console.log(`Last release tag: ${lastTag}`);
} catch {
console.log('No previous tag found. This is the first release.');
}

const commitRange = lastTag ? `${lastTag}..HEAD` : 'HEAD';
const releaseNotes = execSync(
`git log ${commitRange} --pretty=format:"* %s (%h)" --no-merges | grep -v 'github-actions\$begin:math:display$bot\\$end:math:display$'`
).toString();

if (!releaseNotes) {
console.log(
'No new commits since the last release (excluding bot commits).'
);
} else {
console.log('Generated release notes:');
console.log(releaseNotes);
}

execSync(`git tag -a v${version} -m "Release v${version}"`, {
stdio: 'inherit',
});

// Push the tag to the remote repository
execSync(`git push origin v${version}`, {
stdio: 'inherit',
});

// Create a GitHub release
execSync(
`gh release create v${version} --title "Release v${version}" --notes "Automated release for version v${version}"`,
`gh release create v${version} --title "Release v${version}" --notes "${releaseNotes || 'No changes'}"`,
{
stdio: 'inherit',
}
Expand Down
10 changes: 7 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import * as core from '@actions/core';
import { run } from './run';

run().catch((error) => {
core.setFailed(`Unable to upload build due to error: ${error.message}`);
});
run()
.then(() => {
core.info('Build upload process completed successfully');
})
.catch((error) => {
core.setFailed(`Unable to upload build due to error: ${error.message}`);
});
1 change: 0 additions & 1 deletion src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,4 @@ export async function run() {
});

core.setOutput('buildId', buildId);
core.info('Build upload process completed successfully');
}
Loading