From 8df31fb97ebd73e71b2f8a9dc925fe8a81192be3 Mon Sep 17 00:00:00 2001 From: "Max P." Date: Fri, 4 Jul 2025 11:43:25 +0200 Subject: [PATCH] refactor(action): simplify composite action structure - Replaces custom with-post-step logic with Node.js-based implementation - Consolidates main and post scripts for clarity and maintainability - Updates descriptions and input definitions for improved readability --- action.yml | 57 ++++++++++++++------------------------- dist/main.js | 34 +++++++++++++++++++++++ dist/post.js | 31 +++++++++++++++++++++ with-post-step/action.yml | 11 -------- with-post-step/main.js | 18 ------------- 5 files changed, 85 insertions(+), 66 deletions(-) create mode 100644 dist/main.js create mode 100644 dist/post.js delete mode 100644 with-post-step/action.yml delete mode 100644 with-post-step/main.js diff --git a/action.yml b/action.yml index a20db4c..597bad3 100644 --- a/action.yml +++ b/action.yml @@ -1,46 +1,29 @@ -name: "Auto Changelog & Release" -description: "Detects version bump and, in post-step, writes changelog or publishes release." +name: Auto Changelog & Release +description: One-stop composite action inputs: - token: { description: "Gitea/GitHub PAT", default: "" } - author_name: { description: "Commit author", default: "" } - author_email: { description: "Commit e-mail", default: "" } + token: + description: "Gitea/GitHub PAT für Release-API" + required: false + default: "" + author_name: + description: "Commit-Autorname" + required: false + default: "" + author_email: + description: "Commit-Autore-Mail" + required: false + default: "" allow_non_main_release: - description: "Allow release on branches ≠ main" + description: "Allow publishing releases from branches other than 'main'." + required: false default: "false" outputs: release: - description: "true if VERSION changed" - value: ${{ steps.detect.outputs.version_changed }} + description: "Whether a release should be made (true/false)" runs: - using: composite - steps: - - id: detect - name: Detect version change + queue post work - uses: ./with-post-step - with: - key: AUTOCHANGELOG - #################### MAIN #################### - main: | - ${{ github.action_path }}/scripts/detect-version-change.sh - #################### POST #################### - post: | - #!/usr/bin/env bash - set -euo pipefail - # VERSION_CHANGED kommt aus detect-Script via $GITHUB_ENV - CLIFF_VERSION="$( - ${{ github.action_path }}/scripts/read-cliff-version.sh | tail -n1 - )" - "${{ github.action_path }}/scripts/install-git-cliff.sh" "$CLIFF_VERSION" - "${{ github.action_path }}/scripts/setup-git.sh" \ - "${{ inputs.author_name }}" "${{ inputs.author_email }}" - if [[ "${VERSION_CHANGED:-false}" == "true" ]]; then - # --- Release-Pfad --- - RELEASE_PUBLISH_TOKEN='${{ inputs.token }}' \ - "${{ github.action_path }}/scripts/release-from-version.sh" - else - # --- Nur Changelog aktualisieren --- - "${{ github.action_path }}/scripts/generate-unreleased-changelog.sh" - fi + using: "node20" + main: "dist/main.js" + post: "dist/post.js" diff --git a/dist/main.js b/dist/main.js new file mode 100644 index 0000000..6aee5ab --- /dev/null +++ b/dist/main.js @@ -0,0 +1,34 @@ +const cp = require("child_process"); +const path = require("path"); +const fs = require("fs"); + +function run(script) { + cp.execFileSync(script, { stdio: "inherit", shell: true }); +} + +function exportOutput(key, value) { + fs.appendFileSync(process.env.GITHUB_OUTPUT, `${key}=${value}\n`); +} + +function setEnv(key, value) { + fs.appendFileSync(process.env.GITHUB_ENV, `${key}=${value}\n`); +} + +function main() { + const actionPath = process.env.GITHUB_ACTION_PATH || "."; + const script = path.join(actionPath, "scripts/detect-version-change.sh"); + + run(script); + + // Hier nehmen wir an, dass das Script selbst bereits `version_changed=true/false` + // in $GITHUB_OUTPUT geschrieben hat. + // Zur Sicherheit lesen wir das nochmal aus und speichern es auch als release-Flag. + const output = fs.readFileSync(process.env.GITHUB_OUTPUT, "utf-8"); + const match = output.match(/^version_changed=(.*)$/m); + const value = match?.[1]?.trim() || "false"; + + exportOutput("release", value); + setEnv("VERSION_CHANGED", value); +} + +main(); diff --git a/dist/post.js b/dist/post.js new file mode 100644 index 0000000..d327432 --- /dev/null +++ b/dist/post.js @@ -0,0 +1,31 @@ +const cp = require("child_process"); +const path = require("path"); + +function run(script, args = []) { + cp.execFileSync(script, { + stdio: "inherit", + shell: true, + env: process.env, + }); +} + +function main() { + const actionPath = process.env.GITHUB_ACTION_PATH || "."; + const versionChanged = (process.env.VERSION_CHANGED || "false").toLowerCase() === "true"; + + const readCliff = path.join(actionPath, "scripts/read-cliff-version.sh"); + const cliffVersion = cp.execSync(readCliff, { encoding: "utf-8", shell: true }).trim().split("\n").pop(); + + run(path.join(actionPath, "scripts/install-git-cliff.sh"), [cliffVersion]); + + run(`${path.join(actionPath, "scripts/setup-git.sh")} "${process.env.INPUT_AUTHOR_NAME}" "${process.env.INPUT_AUTHOR_EMAIL}"`); + + if (versionChanged) { + process.env.RELEASE_PUBLISH_TOKEN = process.env.INPUT_TOKEN || ""; + run(path.join(actionPath, "scripts/release-from-version.sh")); + } else { + run(path.join(actionPath, "scripts/generate-unreleased-changelog.sh")); + } +} + +main(); diff --git a/with-post-step/action.yml b/with-post-step/action.yml deleted file mode 100644 index 0682124..0000000 --- a/with-post-step/action.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: "with-post-step" -description: "Runs a main command and, afterwards, a post command." -inputs: - main: { description: "Command for the main step", required: true } - post: { description: "Command for the post step", required: true } - key: { description: "State key", default: POST } - -runs: - using: node20 - main: main.js - post: main.js diff --git a/with-post-step/main.js b/with-post-step/main.js deleted file mode 100644 index 8a8797f..0000000 --- a/with-post-step/main.js +++ /dev/null @@ -1,18 +0,0 @@ -const { spawn } = require("child_process"); -const { appendFileSync } = require("fs"); -const { EOL } = require("os"); - -function run(cmd) { - const proc = spawn(cmd, { stdio: "inherit", shell: true }); - proc.on("exit", code => process.exitCode = code); -} - -const key = process.env.INPUT_KEY.toUpperCase(); -if (process.env[`STATE_${key}`] !== undefined) { - // ---------- POST ---------- - run(process.env.INPUT_POST); -} else { - // ---------- MAIN ---------- - appendFileSync(process.env.GITHUB_STATE, `${key}=true${EOL}`); - run(process.env.INPUT_MAIN); -}