Skip to content
Closed
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
75 changes: 0 additions & 75 deletions .github/workflows/pr-version-preview.yml

This file was deleted.

82 changes: 82 additions & 0 deletions .github/workflows/pr-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: PR Version Preview

on:
pull_request:
branches: [main]

permissions:
pull-requests: write
contents: read

jobs:
preview:
runs-on: ubuntu-latest

steps:
# 1️⃣ Checkout full history and all tags
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true

# 2️⃣ Get latest tag and calculate next version
- name: Get latest tag and bump type
id: version
run: |
# Be defensive and robust: use awk to split version numbers and always quote $GITHUB_OUTPUT
git fetch --tags || true
current=$(git describe --tags --abbrev=0 2>/dev/null || true)
if [ -z "$current" ]; then
echo "No tags found, defaulting to v0.0.0"
current="v0.0.0"
fi

# Remove leading 'v' then extract parts using awk
ver=${current#v}
major=$(printf "%s" "$ver" | awk -F. '{print $1+0}')
minor=$(printf "%s" "$ver" | awk -F. '{print $2+0}')
patch=$(printf "%s" "$ver" | awk -F. '{print $3+0}')

# Determine bump type from PR labels (safe interpolation)
LABELS="${{ join(github.event.pull_request.labels.*.name, ' ') }}"
if printf "%s" "$LABELS" | grep -q "major"; then
major=$((major+1)); minor=0; patch=0; type="major"
elif printf "%s" "$LABELS" | grep -q "minor"; then
minor=$((minor+1)); patch=0; type="minor"
else
patch=$((patch+1)); type="patch"
fi

next="v${major}.${minor}.${patch}"

# Safely write outputs
if [ -n "$GITHUB_OUTPUT" ]; then
# Write all outputs in one redirect to avoid multiple open/close
{
printf '%s\n' "current=$current" "next=$next" "type=$type"
} >> "$GITHUB_OUTPUT"
else
# Fallback to printing if GITHUB_OUTPUT not available (for local debugging)
echo "current=$current"
echo "next=$next"
echo "type=$type"
fi

# 3️⃣ Optional debug: show what tags exist and the next version
- name: Debug current tags
run: |
echo "Git tags in this repo:"
git tag -l
echo "Current latest tag: ${{ steps.version.outputs.current }}"
echo "Predicted next version: ${{ steps.version.outputs.next }}"

# 4️⃣ Comment predicted version on PR
- name: Comment version preview
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
🧩 **Version Preview**
Current latest tag: `${{ steps.version.outputs.current }}`
PR labels: `${{ join(github.event.pull_request.labels.*.name, ', ') }}`
➡️ **Predicted next version on merge:** **${{ steps.version.outputs.next }}**
27 changes: 25 additions & 2 deletions .github/workflows/publish-mod-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
contents: read
packages: write
env:
DOTNET_VERSION: 8.0
PROJECT: src/MyLibrary/MyLibrary.csproj
DOTNET_VERSION: 9.0
PROJECT: StarMap.API/StarMap.API.csproj
OUTPUT: ./nupkg
NUGET_SOURCE: "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"

Expand All @@ -28,11 +28,34 @@ jobs:
id: version
run: echo "version=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT

- name: Check whether StarMap.API changed since previous tag
id: check
run: |
git fetch --tags
current=${GITHUB_REF_NAME}
# Get previous tag by creation date; empty if none
prev=$(git tag --sort=-creatordate | sed -n '2p' || true)
echo "previous_tag=$prev" >> $GITHUB_OUTPUT
if [ -z "$prev" ]; then
echo "changed=true" >> $GITHUB_OUTPUT
exit 0
fi
# Show diff between previous tag and this tag
diff=$(git diff --name-only "$prev" "refs/tags/$current")
echo "diff_files=$diff" >> $GITHUB_OUTPUT
if echo "$diff" | grep -qE '^StarMap.API/|^StarMap.API.csproj'; then
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "changed=false" >> $GITHUB_OUTPUT
fi

- name: Pack library
if: steps.check.outputs.changed == 'true'
run: dotnet pack ${{ env.PROJECT }} -c Release -o ${{ env.OUTPUT }} /p:PackageVersion=${{ steps.version.outputs.version }}

- name: Add GitHub Packages source
run: dotnet nuget add source --username "${{ github.actor }}" --password "${{ secrets.GITHUB_TOKEN }}" --store-password-in-clear-text --name github ${{ env.NUGET_SOURCE }}

- name: Push to GitHub Packages
if: steps.check.outputs.changed == 'true'
run: dotnet nuget push ${{ env.OUTPUT }}/*.nupkg --source github --api-key "${{ secrets.GITHUB_TOKEN }}" --skip-duplicate
10 changes: 7 additions & 3 deletions .github/workflows/release-zip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ jobs:
permissions:
contents: write
env:
DOTNET_VERSION: 8.0
PROJECT: src/MyApp/MyApp.csproj
DOTNET_VERSION: 9.0
PROJECT: StarMapLoader/StarMapLoader.csproj
OUTPUT_PATH: ./publish
# Customize what to exclude from the created ZIP (space-separated patterns)
EXCLUDE: "*.pdb *.xml DummyProgram/*"

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -67,7 +69,9 @@ jobs:
- name: Package ZIP
run: |
cd ${{ env.OUTPUT_PATH }}
zip -r ../../release-${{ steps.version.outputs.new }}.zip . -x "*.pdb" "*.xml"
# EXCLUDE contains space-separated patterns to pass to zip -x
# Use parameter expansion so multiple patterns are honored.
zip -r ../../release-${{ steps.version.outputs.new }}.zip . -x ${EXCLUDE}
cd -

- name: Create GitHub Release
Expand Down
2 changes: 1 addition & 1 deletion StarMapLoader/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace StarMapLoader
{
internal class Program
{
{//This is for a test
static void Main(string[] args)
{
MainInner().GetAwaiter().GetResult();
Expand Down