From 57cbc5a0efef150a211574388572c12073a9af75 Mon Sep 17 00:00:00 2001 From: Martin Bonnin Date: Wed, 19 Jun 2024 16:47:07 +0200 Subject: [PATCH] Add tag-version github action --- tag-version/action.yml | 11 +++++++++++ tag-version/index.js | 34 ++++++++++++++++++++++++++++++++ tag-version/tag-version.main.kts | 18 +++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 tag-version/action.yml create mode 100644 tag-version/index.js create mode 100644 tag-version/tag-version.main.kts diff --git a/tag-version/action.yml b/tag-version/action.yml new file mode 100644 index 0000000..4ceba56 --- /dev/null +++ b/tag-version/action.yml @@ -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' + diff --git a/tag-version/index.js b/tag-version/index.js new file mode 100644 index 0000000..83ff95f --- /dev/null +++ b/tag-version/index.js @@ -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); +}) \ No newline at end of file diff --git a/tag-version/tag-version.main.kts b/tag-version/tag-version.main.kts new file mode 100644 index 0000000..bddc3c9 --- /dev/null +++ b/tag-version/tag-version.main.kts @@ -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")) \ No newline at end of file