From d60788c90f8935caf6567d6faa158c0f208894b2 Mon Sep 17 00:00:00 2001 From: dutchie031 Date: Fri, 24 Jul 2026 21:53:20 +0200 Subject: [PATCH] trying out entire action --- .github/workflows/publish-github-action.yml | 321 +++++++++----------- 1 file changed, 148 insertions(+), 173 deletions(-) diff --git a/.github/workflows/publish-github-action.yml b/.github/workflows/publish-github-action.yml index 76dbfb2..24837e2 100644 --- a/.github/workflows/publish-github-action.yml +++ b/.github/workflows/publish-github-action.yml @@ -4,17 +4,16 @@ on: push: branches: - main - # paths: - # - github-action/package.json + paths: + - github-action/package.json permissions: contents: write jobs: - - test: - name: Test action - runs-on: ubuntu-latest + verify_action: + name: Verify action + runs-on: linux steps: - name: Checkout repository uses: actions/checkout@v4 @@ -32,194 +31,170 @@ jobs: working-directory: github-action run: npm ci - - name: Run action tests - working-directory: github-action - run: npm test + - name: Create verification fixture + shell: bash + run: | + mkdir -p test-action-input + cat <<'EOF' > test-action-input/main.lua + local message = {} - # verify_action: - # name: Verify action - # runs-on: linux - # steps: - # - name: Checkout repository - # uses: actions/checkout@v4 - # with: - # fetch-depth: 0 + message.hello = function() + return "hello" + end - # - name: Set up Node.js - # uses: actions/setup-node@v4 - # with: - # node-version: 22 - # cache: npm - # cache-dependency-path: github-action/package-lock.json + return message + EOF - # - name: Install action dependencies - # working-directory: github-action - # run: npm ci + - name: Run action locally + uses: ./github-action + with: + source-root: test-action-input + output-file: test-action-output/compiled.lua - # - name: Create verification fixture - # shell: bash - # run: | - # mkdir -p test-action-input - # cat <<'EOF' > test-action-input/main.lua - # local message = {} + - name: Assert compiled output exists + shell: bash + run: test -f test-action-output/compiled.lua - # message.hello = function() - # return "hello" - # end + derive_release: + name: Derive release metadata + runs-on: linux + needs: verify_action + outputs: + version: ${{ steps.derive.outputs.version }} + release_tag: ${{ steps.derive.outputs.release_tag }} + rolling_minor_tag: ${{ steps.derive.outputs.rolling_minor_tag }} + rolling_major_tag: ${{ steps.derive.outputs.rolling_major_tag }} + bump_kind: ${{ steps.derive.outputs.bump_kind }} + should_publish: ${{ steps.derive.outputs.should_publish }} + latest_release_tag: ${{ steps.derive.outputs.latest_release_tag }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 - # return message - # EOF + - name: Derive version and tags + id: derive + shell: bash + run: | + set -euo pipefail - # - name: Run action locally - # uses: ./github-action - # with: - # source-root: test-action-input - # output-file: test-action-output/compiled.lua + version=$(node -p "require('./github-action/package.json').version") + if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "github-action/package.json version must be semver X.Y.Z, got: $version" >&2 + exit 1 + fi - # - name: Assert compiled output exists - # shell: bash - # run: test -f test-action-output/compiled.lua + IFS='.' read -r major minor patch <<< "$version" + release_tag="action/v${version}" + rolling_minor_tag="action/v${major}.${minor}" + rolling_major_tag="action/v${major}" - # derive_release: - # name: Derive release metadata - # runs-on: linux - # needs: verify_action - # outputs: - # version: ${{ steps.derive.outputs.version }} - # release_tag: ${{ steps.derive.outputs.release_tag }} - # rolling_minor_tag: ${{ steps.derive.outputs.rolling_minor_tag }} - # rolling_major_tag: ${{ steps.derive.outputs.rolling_major_tag }} - # bump_kind: ${{ steps.derive.outputs.bump_kind }} - # should_publish: ${{ steps.derive.outputs.should_publish }} - # latest_release_tag: ${{ steps.derive.outputs.latest_release_tag }} - # steps: - # - name: Checkout repository - # uses: actions/checkout@v4 - # with: - # fetch-depth: 0 + latest_release_tag=$(git tag --list 'action/v*.*.*' --sort=-version:refname | head -n 1) - # - name: Derive version and tags - # id: derive - # shell: bash - # run: | - # set -euo pipefail + bump_kind="initial" + should_publish="true" - # version=$(node -p "require('./github-action/package.json').version") - # if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - # echo "github-action/package.json version must be semver X.Y.Z, got: $version" >&2 - # exit 1 - # fi + if [[ -n "$latest_release_tag" ]]; then + latest_version=${latest_release_tag#action/v} - # IFS='.' read -r major minor patch <<< "$version" - # release_tag="action/v${version}" - # rolling_minor_tag="action/v${major}.${minor}" - # rolling_major_tag="action/v${major}" + if [[ "$version" == "$latest_version" ]]; then + should_publish="false" + bump_kind="duplicate" + else + IFS='.' read -r latest_major latest_minor latest_patch <<< "$latest_version" - # latest_release_tag=$(git tag --list 'action/v*.*.*' --sort=-version:refname | head -n 1) + if (( major < latest_major )) || \ + (( major == latest_major && minor < latest_minor )) || \ + (( major == latest_major && minor == latest_minor && patch < latest_patch )); then + echo "github-action/package.json version $version must be greater than latest published $latest_version" >&2 + exit 1 + fi - # bump_kind="initial" - # should_publish="true" + if (( major > latest_major )); then + bump_kind="major" + elif (( minor > latest_minor )); then + bump_kind="minor" + elif (( patch > latest_patch )); then + bump_kind="patch" + else + echo "Unable to derive release kind from $latest_version -> $version" >&2 + exit 1 + fi + fi + fi - # if [[ -n "$latest_release_tag" ]]; then - # latest_version=${latest_release_tag#action/v} + echo "version=$version" >> "$GITHUB_OUTPUT" + echo "release_tag=$release_tag" >> "$GITHUB_OUTPUT" + echo "rolling_minor_tag=$rolling_minor_tag" >> "$GITHUB_OUTPUT" + echo "rolling_major_tag=$rolling_major_tag" >> "$GITHUB_OUTPUT" + echo "bump_kind=$bump_kind" >> "$GITHUB_OUTPUT" + echo "should_publish=$should_publish" >> "$GITHUB_OUTPUT" + echo "latest_release_tag=$latest_release_tag" >> "$GITHUB_OUTPUT" - # if [[ "$version" == "$latest_version" ]]; then - # should_publish="false" - # bump_kind="duplicate" - # else - # IFS='.' read -r latest_major latest_minor latest_patch <<< "$latest_version" + - name: Summarize release plan + shell: bash + run: | + { + echo "## Action release plan" + echo "" + echo "- Version: ${{ steps.derive.outputs.version }}" + echo "- Release tag: ${{ steps.derive.outputs.release_tag }}" + echo "- Rolling minor tag: ${{ steps.derive.outputs.rolling_minor_tag }}" + echo "- Rolling major tag: ${{ steps.derive.outputs.rolling_major_tag }}" + echo "- Bump kind: ${{ steps.derive.outputs.bump_kind }}" + echo "- Latest published tag: ${{ steps.derive.outputs.latest_release_tag || 'none' }}" + echo "- Will publish: ${{ steps.derive.outputs.should_publish }}" + } >> "$GITHUB_STEP_SUMMARY" - # if (( major < latest_major )) || \ - # (( major == latest_major && minor < latest_minor )) || \ - # (( major == latest_major && minor == latest_minor && patch < latest_patch )); then - # echo "github-action/package.json version $version must be greater than latest published $latest_version" >&2 - # exit 1 - # fi + publish_tags: + name: Publish tags + runs-on: linux + needs: derive_release + if: ${{ needs.derive_release.outputs.should_publish == 'true' }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 - # if (( major > latest_major )); then - # bump_kind="major" - # elif (( minor > latest_minor )); then - # bump_kind="minor" - # elif (( patch > latest_patch )); then - # bump_kind="patch" - # else - # echo "Unable to derive release kind from $latest_version -> $version" >&2 - # exit 1 - # fi - # fi - # fi + - name: Create immutable release tag + shell: bash + run: | + set -euo pipefail + release_tag='${{ needs.derive_release.outputs.release_tag }}' - # echo "version=$version" >> "$GITHUB_OUTPUT" - # echo "release_tag=$release_tag" >> "$GITHUB_OUTPUT" - # echo "rolling_minor_tag=$rolling_minor_tag" >> "$GITHUB_OUTPUT" - # echo "rolling_major_tag=$rolling_major_tag" >> "$GITHUB_OUTPUT" - # echo "bump_kind=$bump_kind" >> "$GITHUB_OUTPUT" - # echo "should_publish=$should_publish" >> "$GITHUB_OUTPUT" - # echo "latest_release_tag=$latest_release_tag" >> "$GITHUB_OUTPUT" + if git rev-parse "$release_tag" >/dev/null 2>&1; then + echo "Release tag $release_tag already exists" >&2 + exit 1 + fi - # - name: Summarize release plan - # shell: bash - # run: | - # { - # echo "## Action release plan" - # echo "" - # echo "- Version: ${{ steps.derive.outputs.version }}" - # echo "- Release tag: ${{ steps.derive.outputs.release_tag }}" - # echo "- Rolling minor tag: ${{ steps.derive.outputs.rolling_minor_tag }}" - # echo "- Rolling major tag: ${{ steps.derive.outputs.rolling_major_tag }}" - # echo "- Bump kind: ${{ steps.derive.outputs.bump_kind }}" - # echo "- Latest published tag: ${{ steps.derive.outputs.latest_release_tag || 'none' }}" - # echo "- Will publish: ${{ steps.derive.outputs.should_publish }}" - # } >> "$GITHUB_STEP_SUMMARY" + git tag "$release_tag" "$GITHUB_SHA" - # publish_tags: - # name: Publish tags - # runs-on: linux - # needs: derive_release - # if: ${{ needs.derive_release.outputs.should_publish == 'true' }} - # steps: - # - name: Checkout repository - # uses: actions/checkout@v4 - # with: - # fetch-depth: 0 + - name: Update rolling tags + shell: bash + run: | + set -euo pipefail + git tag -f '${{ needs.derive_release.outputs.rolling_minor_tag }}' "$GITHUB_SHA" + git tag -f '${{ needs.derive_release.outputs.rolling_major_tag }}' "$GITHUB_SHA" - # - name: Create immutable release tag - # shell: bash - # run: | - # set -euo pipefail - # release_tag='${{ needs.derive_release.outputs.release_tag }}' + - name: Push release tags + shell: bash + run: | + set -euo pipefail + git push origin '${{ needs.derive_release.outputs.release_tag }}' + git push origin '${{ needs.derive_release.outputs.rolling_minor_tag }}' --force + git push origin '${{ needs.derive_release.outputs.rolling_major_tag }}' --force - # if git rev-parse "$release_tag" >/dev/null 2>&1; then - # echo "Release tag $release_tag already exists" >&2 - # exit 1 - # fi - - # git tag "$release_tag" "$GITHUB_SHA" - - # - name: Update rolling tags - # shell: bash - # run: | - # set -euo pipefail - # git tag -f '${{ needs.derive_release.outputs.rolling_minor_tag }}' "$GITHUB_SHA" - # git tag -f '${{ needs.derive_release.outputs.rolling_major_tag }}' "$GITHUB_SHA" - - # - name: Push release tags - # shell: bash - # run: | - # set -euo pipefail - # git push origin '${{ needs.derive_release.outputs.release_tag }}' - # git push origin '${{ needs.derive_release.outputs.rolling_minor_tag }}' --force - # git push origin '${{ needs.derive_release.outputs.rolling_major_tag }}' --force - - # - name: Summarize published tags - # shell: bash - # run: | - # { - # echo "## Published action tags" - # echo "" - # echo "- Immutable: ${{ needs.derive_release.outputs.release_tag }}" - # echo "- Rolling minor: ${{ needs.derive_release.outputs.rolling_minor_tag }}" - # echo "- Rolling major: ${{ needs.derive_release.outputs.rolling_major_tag }}" - # echo "- Bump kind: ${{ needs.derive_release.outputs.bump_kind }}" - # } >> "$GITHUB_STEP_SUMMARY" + - name: Summarize published tags + shell: bash + run: | + { + echo "## Published action tags" + echo "" + echo "- Immutable: ${{ needs.derive_release.outputs.release_tag }}" + echo "- Rolling minor: ${{ needs.derive_release.outputs.rolling_minor_tag }}" + echo "- Rolling major: ${{ needs.derive_release.outputs.rolling_major_tag }}" + echo "- Bump kind: ${{ needs.derive_release.outputs.bump_kind }}" + } >> "$GITHUB_STEP_SUMMARY"