Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 200 additions & 0 deletions .github/workflows/publish-github-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
name: Publish GitHub Action

on:
push:
branches:
- main
paths:
- github-action/package.json

permissions:
contents: write

jobs:
verify_action:
name: Verify 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: 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: ubuntu-latest
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: ubuntu-latest
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"

12 changes: 12 additions & 0 deletions .github/workflows/publish-vs-code-extensions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
on:
push:
branches:
- main

jobs:
publish:
name: Publish VS Code Extension
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
2 changes: 0 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// for the documentation about the extensions.json format
"recommendations": [
"dbaeumer.vscode-eslint",
"connor4312.esbuild-problem-matchers",
"ms-vscode.extension-test-runner",
"sumneko.lua"
]
}
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"${workspaceFolder}/dutchies-dcs-scripting-tools/dist/**/*.js",
"${workspaceFolder}/compiler/dist/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
"preLaunchTask": "watch"
}
]
}
78 changes: 19 additions & 59 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,30 @@
"version": "2.0.0",
"tasks": [
{
"label": "watch",
"dependsOn": [
"npm: watch:tsc",
"npm: watch:esbuild"
],
"presentation": {
"reveal": "never"
},
"group": {
"kind": "build",
"isDefault": true
},
"options": {
"cwd": "${workspaceFolder}/dutchies-dcs-scripting-tools"
}
},
{
"type": "npm",
"script": "watch:esbuild",
"group": "build",
"problemMatcher": "$esbuild-watch",
"isBackground": true,
"label": "npm: watch:esbuild",
"presentation": {
"group": "watch",
"reveal": "never"
},
"options": {
"cwd": "${workspaceFolder}/dutchies-dcs-scripting-tools"
}
},
{
"type": "npm",
"script": "watch:tsc",
"group": "build",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"label": "npm: watch:tsc",
"presentation": {
"group": "watch",
"reveal": "never"
},
"options": {
"cwd": "${workspaceFolder}/dutchies-dcs-scripting-tools"
}
},
"label": "compile",
"type": "npm",
"script": "compile",
"group": {
"kind": "build",
"isDefault": true
},
"options": {
"cwd": "${workspaceFolder}/dutchies-dcs-scripting-tools"
}
},
{
"label": "watch",
"type": "npm",
"script": "watch-tests",
"problemMatcher": "$tsc-watch",
"script": "watch",
"isBackground": true,
"presentation": {
"reveal": "never",
"group": "watchers"
"reveal": "never"
},
"group": "build"
},
{
"label": "tasks: watch-tests",
"dependsOn": [
"npm: watch",
"npm: watch-tests"
],
"problemMatcher": []
"group": "build",
"problemMatcher": "$tsc-watch",
"options": {
"cwd": "${workspaceFolder}/dutchies-dcs-scripting-tools"
}
}
]
}
Loading