Skip to content

Commit

Permalink
chore: Updated release process to include sponsorship suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
BottlecapDave committed Oct 11, 2023
1 parent af55287 commit 72f5a30
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 51 deletions.
53 changes: 53 additions & 0 deletions .build/createGithubRelease.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const bodySuffix = "---\nEnjoying the integration? Why not make a one time or monthly [GitHub sponsorship](https://github.com/sponsors/bottlecapdave)?"

async function createGithubRelease(githubToken: string, githubOwnerRepo: string, tag: string, notes: string) {
if (!githubToken) {
throw new Error('Github token not specified');
}

if (!githubOwnerRepo) {
throw new Error('Github owner/repo not specified');
}

if (!tag) {
throw new Error('Tag not specified');
}

if (!notes) {
throw new Error('Notes not specified');
}

console.log(`Publishing ${tag} release to ${githubOwnerRepo}`);

const body = JSON.stringify({
tag_name: tag,
name: tag,
body: notes,
draft: false,
prerelease:false
});

const response = await fetch(
`https://api.github.com/repos/${githubOwnerRepo}/releases`,
{
method: 'POST',
headers: {
"Accept": "application/vnd.github+json",
"Authorization": `Bearer ${githubToken}`,
"X-GitHub-Api-Version": "2022-11-28"
},
body
}
);

if (response.status >= 300) {
throw new Error(response.statusText);
}
}

createGithubRelease(
process.env.GITHUB_TOKEN,
process.env.GITHUB_REPOSITORY,
process.argv[2],
`${process.argv[3]}\n${bodySuffix}`
).then(() => console.log('Success'));
12 changes: 12 additions & 0 deletions .build/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"alwaysStrict": true,
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true,

},
"include": ["**/*"]
}
14 changes: 0 additions & 14 deletions .build/update-manifest.js

This file was deleted.

16 changes: 16 additions & 0 deletions .build/updateManifest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { readFileSync, writeFileSync } from 'fs';
import { join } from 'path';

const filePath = join(__dirname, '../custom_components/harvest_time_tracker/manifest.json');

function updateManifest(version: string) {

const buffer = readFileSync(filePath);
const content = JSON.parse(buffer.toString());
content.version = version;

writeFileSync(filePath, JSON.stringify(content, null, 2));
console.log(`Updated version to '${version}'`);
}

updateManifest(process.argv[2]);
10 changes: 7 additions & 3 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"branches": ["master"],
"branches": ["main", "develop"],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
Expand All @@ -9,17 +9,21 @@
"changelogFile": "CHANGELOG.md"
}
],
"@semantic-release/github",
[
"@semantic-release/exec", {
"prepareCmd" : "node .build/update-manifest ${nextRelease.version}"
"prepareCmd" : "ts-node .build/updateManifest.ts ${nextRelease.version}"
}
],
[
"@semantic-release/git", {
"assets": ["package.json", "CHANGELOG.md", "./custom_components/harvest_time_tracker/manifest.json"],
"message": "release: Released v${nextRelease.version} [skip ci]"
}
],
[
"@semantic-release/exec", {
"publishCmd" : "ts-node .build/createGithubRelease.ts v${nextRelease.version} \"${nextRelease.notes}\""
}
]
]
}
50 changes: 17 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Home Assistant integration for interacting with Harvest Time Tracker",
"main": "index.js",
"scripts": {
"build": "tsc ./.build/*.ts --noEmit",
"commit": "cz",
"release": "semantic-release",
"test-unit": "python -m pytest tests/unit",
Expand All @@ -27,7 +28,9 @@
"conventional-changelog-eslint": "^4.0.0",
"cz-customizable": "^7.0.0",
"husky": "^4.3.8",
"semantic-release": "^21.0.5"
"semantic-release": "^21.0.5",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
},
"config": {
"commitizen": {
Expand Down

0 comments on commit 72f5a30

Please sign in to comment.