226 lines
7.8 KiB
YAML
226 lines
7.8 KiB
YAML
name: Publish GitHub Action
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
# paths:
|
|
# - github-action/package.json
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
jobs:
|
|
|
|
test:
|
|
name: Test action
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Set up Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 22
|
|
cache: npm
|
|
cache-dependency-path: github-action/package-lock.json
|
|
|
|
- name: Install action dependencies
|
|
working-directory: github-action
|
|
run: npm ci
|
|
|
|
- name: Run action tests
|
|
working-directory: github-action
|
|
run: npm test
|
|
|
|
# verify_action:
|
|
# name: Verify action
|
|
# runs-on: linux
|
|
# steps:
|
|
# - name: Checkout repository
|
|
# uses: actions/checkout@v4
|
|
# with:
|
|
# fetch-depth: 0
|
|
|
|
# - name: Set up Node.js
|
|
# uses: actions/setup-node@v4
|
|
# with:
|
|
# node-version: 22
|
|
# cache: npm
|
|
# cache-dependency-path: github-action/package-lock.json
|
|
|
|
# - name: Install action dependencies
|
|
# working-directory: github-action
|
|
# run: npm ci
|
|
|
|
# - name: Create verification fixture
|
|
# shell: bash
|
|
# run: |
|
|
# mkdir -p test-action-input
|
|
# cat <<'EOF' > test-action-input/main.lua
|
|
# local message = {}
|
|
|
|
# message.hello = function()
|
|
# return "hello"
|
|
# end
|
|
|
|
# return message
|
|
# EOF
|
|
|
|
# - name: Run action locally
|
|
# uses: ./github-action
|
|
# with:
|
|
# source-root: test-action-input
|
|
# output-file: test-action-output/compiled.lua
|
|
|
|
# - name: Assert compiled output exists
|
|
# shell: bash
|
|
# run: test -f test-action-output/compiled.lua
|
|
|
|
# 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
|
|
|
|
# - name: Derive version and tags
|
|
# id: derive
|
|
# shell: bash
|
|
# run: |
|
|
# set -euo pipefail
|
|
|
|
# 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
|
|
|
|
# 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}"
|
|
|
|
# latest_release_tag=$(git tag --list 'action/v*.*.*' --sort=-version:refname | head -n 1)
|
|
|
|
# bump_kind="initial"
|
|
# should_publish="true"
|
|
|
|
# if [[ -n "$latest_release_tag" ]]; then
|
|
# latest_version=${latest_release_tag#action/v}
|
|
|
|
# if [[ "$version" == "$latest_version" ]]; then
|
|
# should_publish="false"
|
|
# bump_kind="duplicate"
|
|
# else
|
|
# IFS='.' read -r latest_major latest_minor latest_patch <<< "$latest_version"
|
|
|
|
# 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
|
|
|
|
# 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
|
|
|
|
# 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"
|
|
|
|
# - 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"
|
|
|
|
# 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: Create immutable release tag
|
|
# shell: bash
|
|
# run: |
|
|
# set -euo pipefail
|
|
# release_tag='${{ needs.derive_release.outputs.release_tag }}'
|
|
|
|
# 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"
|
|
|