Skip to content

Commit

Permalink
Add tag-version github action
Browse files Browse the repository at this point in the history
  • Loading branch information
martinbonnin committed Jun 19, 2024
1 parent 1e6a389 commit 57cbc5a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tag-version/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: 'Tag version'
description: 'Sets the version to "versionToRelease", creates a tag and bump to the next patch SNAPSHOT'
inputs:
versionToRelease:
description: 'The version to release'
required: true

runs:
using: 'node20'
main: 'index.js'

34 changes: 34 additions & 0 deletions tag-version/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Most of this code has been copied from the following GitHub Action
* to make it simpler or not necessary to install a lot of
* JavaScript packages to execute a shell script.
*
* https://github.com/ad-m/github-push-action/blob/fe38f0a751bf9149f0270cc1fe20bf9156854365/start.js
*/

const spawn = require('child_process').spawn;
const path = require("path");

const exec = (cmd, args=[]) => new Promise((resolve, reject) => {
console.log(`Started: ${cmd} ${args.join(" ")}`)
const app = spawn(cmd, args, { stdio: 'inherit' });
app.on('close', code => {
if(code !== 0){
err = new Error(`Invalid status code: ${code}`);
err.code = code;
return reject(err);
};
return resolve(code);
});
app.on('error', reject);
});

const main = async () => {
await exec('kotlin', [path.join(__dirname, './tag-version.main.kts')]);
};

main().catch(err => {
console.error(err);
console.error(err.stack);
process.exit(err.code || -1);
})
18 changes: 18 additions & 0 deletions tag-version/tag-version.main.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env kotlin

@file:DependsOn("com.gradleup.librarian:core:0.0.3")

import com.gradleup.librarian.core.tooling.commitRelease


fun getInput(name: String): String {
return getOptionalInput(name) ?: error("Cannot find an input for $name")
}

fun getOptionalInput(name: String): String? {
return System.getenv("INPUT_${name.uppercase()}")?.ifBlank {
null
}
}

commitRelease(getInput("versionToRelease"))

0 comments on commit 57cbc5a

Please sign in to comment.