Skip to content

build(release): publish dev on main updates #2

build(release): publish dev on main updates

build(release): publish dev on main updates #2

Workflow file for this run

name: Build and publish SampSharp releases
on:
push:
branches: [main]
paths:
- .github/workflows/component-native.yml
- .github/workflows/dotnet-libraries.yml
- .github/workflows/release.yml
- src/**
- external/**
- test/**
- SampSharp.slnx
- Directory.Build.props
- build.cmd
- build.sh
workflow_dispatch:
inputs:
source_ref:
description: Branch, tag, or commit to build
required: true
default: main
type: string
release_version:
description: Optional immutable stable version (for example 1.0.0)
required: false
default: ""
type: string
push_dev:
description: Update the mutable dev release
required: true
default: true
type: boolean
native_consumers_green:
description: Confirm consuming gamemodes passed native macOS validation
required: true
default: false
type: boolean
permissions:
contents: read
concurrency:
group: publish-sampsharp
cancel-in-progress: ${{ github.event_name == 'push' }}
jobs:
validate:
name: Validate release request
runs-on: ubuntu-24.04
outputs:
revision: ${{ steps.source.outputs.revision }}
dev_version: ${{ steps.source.outputs.dev_version }}
publish_dev: ${{ steps.source.outputs.publish_dev }}
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event_name == 'push' && github.sha || inputs.source_ref }}
clean: true
fetch-depth: 0
- name: Pin source and validate inputs
id: source
env:
RELEASE_VERSION: ${{ inputs.release_version }}
PUSH_DEV: ${{ github.event_name == 'push' || inputs.push_dev }}
CONSUMERS_GREEN: ${{ github.event_name == 'push' || inputs.native_consumers_green }}
shell: bash
run: |
if [[ "$CONSUMERS_GREEN" != true ]]; then
echo "::error::Consuming gamemodes must pass native macOS validation before publication."
exit 1
fi
if [[ -z "$RELEASE_VERSION" && "$PUSH_DEV" != true ]]; then
echo "::error::Set a release version or enable Push to dev."
exit 1
fi
if [[ -n "$RELEASE_VERSION" ]]; then
[[ "$RELEASE_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9][A-Za-z0-9.-]*)?$ ]]
git check-ref-format "refs/tags/$RELEASE_VERSION"
if git ls-remote --exit-code --tags origin "refs/tags/$RELEASE_VERSION" >/dev/null 2>&1; then
echo "::error::Release $RELEASE_VERSION already exists; versions are immutable."
exit 1
fi
fi
revision=$(git rev-parse HEAD)
short_revision=$(git rev-parse --short=8 HEAD)
echo "revision=$revision" >> "$GITHUB_OUTPUT"
echo "dev_version=1.0.0-dev.${GITHUB_RUN_NUMBER}.${short_revision}" >> "$GITHUB_OUTPUT"
echo "publish_dev=$PUSH_DEV" >> "$GITHUB_OUTPUT"
native-build:
needs: validate
uses: ./.github/workflows/component-native.yml
with:
source_ref: ${{ needs.validate.outputs.revision }}
libraries:
name: Build, test, and pack managed libraries
needs: validate
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
with:
ref: ${{ needs.validate.outputs.revision }}
clean: true
- uses: actions/setup-dotnet@v5
with:
dotnet-version: 10.0.x
- name: Build and test
run: |
./build.sh libraries
./build.sh libraries test --no-build
- name: Pack dev libraries
if: needs.validate.outputs.publish_dev == 'true'
run: |
./build.sh libraries publish --version="${{ needs.validate.outputs.dev_version }}"
mkdir -p dev-packages
cp build/artifacts/packages/*.{nupkg,snupkg} dev-packages/
- name: Upload dev libraries
if: needs.validate.outputs.publish_dev == 'true'
uses: actions/upload-artifact@v7
with:
name: sampsharp-nuget-dev
path: dev-packages/
if-no-files-found: error
retention-days: 30
- name: Pack versioned libraries
if: inputs.release_version != ''
run: |
rm -rf build/artifacts/packages
./build.sh libraries publish --version="${{ inputs.release_version }}"
mkdir -p version-packages
cp build/artifacts/packages/*.{nupkg,snupkg} version-packages/
- name: Upload versioned libraries
if: inputs.release_version != ''
uses: actions/upload-artifact@v7
with:
name: sampsharp-nuget-versioned
path: version-packages/
if-no-files-found: error
retention-days: 30
publish:
name: Publish selected releases
needs: [validate, native-build, libraries]
runs-on: ubuntu-24.04
environment: release-publish
permissions:
contents: write
steps:
- uses: actions/checkout@v6
with:
ref: ${{ needs.validate.outputs.revision }}
clean: true
fetch-depth: 0
- uses: actions/setup-dotnet@v5
if: inputs.release_version != ''
with:
dotnet-version: 10.0.x
- uses: actions/download-artifact@v8
with:
pattern: sampsharp-component-*
path: native-components
- uses: actions/download-artifact@v8
if: needs.validate.outputs.publish_dev == 'true'
with:
name: sampsharp-nuget-dev
path: dev-packages
- uses: actions/download-artifact@v8
if: inputs.release_version != ''
with:
name: sampsharp-nuget-versioned
path: version-packages
- name: Package native components
shell: bash
run: |
mkdir -p release-assets
for component_dir in native-components/sampsharp-component-*; do
artifact=${component_dir#native-components/sampsharp-component-}
tar -czf "release-assets/SampSharp-component-${artifact}.tar.gz" -C "$component_dir" .
done
- name: Stage checksum-complete release assets
shell: bash
run: |
if [[ "${{ needs.validate.outputs.publish_dev }}" == true ]]; then
mkdir -p dev-release
cp release-assets/* dev-packages/* dev-release/
(cd dev-release && sha256sum * > SHA256SUMS)
fi
if [[ -n "${{ inputs.release_version }}" ]]; then
mkdir -p version-release
cp release-assets/* version-packages/* version-release/
(cd version-release && sha256sum * > SHA256SUMS)
fi
- name: Publish selected releases
env:
GH_TOKEN: ${{ github.token }}
PUSH_DEV: ${{ needs.validate.outputs.publish_dev }}
RELEASE_VERSION: ${{ inputs.release_version }}
REVISION: ${{ needs.validate.outputs.revision }}
DEV_VERSION: ${{ needs.validate.outputs.dev_version }}
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
shell: bash
run: |
if [[ -n "$RELEASE_VERSION" ]]; then
git tag "$RELEASE_VERSION" "$REVISION"
git push origin "refs/tags/$RELEASE_VERSION"
prerelease=()
[[ "$RELEASE_VERSION" != *-* ]] || prerelease+=(--prerelease)
gh release create "$RELEASE_VERSION" version-release/* \
--verify-tag \
--generate-notes \
--notes "Active-development downstream release; APIs and packaging may change before a future stability declaration." \
"${prerelease[@]}" \
--title "SampSharp $RELEASE_VERSION"
for package in version-packages/*.nupkg; do
dotnet nuget push "$package" \
--source https://api.nuget.org/v3/index.json \
--api-key "$NUGET_API_KEY"
done
fi
if [[ "$PUSH_DEV" == true ]]; then
git tag --force dev "$REVISION"
git push origin refs/tags/dev --force
notes="Rolling native and managed build from \`$REVISION\`. NuGet version: \`$DEV_VERSION\`."
if gh release view dev >/dev/null 2>&1; then
gh release edit dev --title "SampSharp development build" --prerelease --notes "$notes"
else
gh release create dev --target "$REVISION" \
--title "SampSharp development build" --prerelease --notes "$notes"
fi
gh release view dev --json assets --jq '.assets[].name' | while IFS= read -r asset; do
[[ -z "$asset" ]] || gh release delete-asset dev "$asset" --yes
done
gh release upload dev dev-release/* --clobber
fi