Add GitHub Actions workflow for SurfTimer.Plugin release #3
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release SurfTimer.Plugin | |
| on: | |
| push: | |
| tags: | |
| - "v*.*.*" | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: "Tag to release (e.g., v1.2.3)" | |
| required: true | |
| default: "v0.0.0" | |
| permissions: | |
| contents: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Resolve release tag | |
| id: vars | |
| shell: bash | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| TAG="${{ github.event.inputs.tag }}" | |
| else | |
| TAG="${{ github.ref_name }}" | |
| fi | |
| if ! echo "$TAG" | grep -Eq '^v[0-9]'; then | |
| echo "Tag must start with 'v' (e.g., v1.2.3). Got: $TAG" | |
| exit 1 | |
| fi | |
| echo "RELEASE_TAG=$TAG" >> $GITHUB_ENV | |
| echo "tag=$TAG" >> $GITHUB_OUTPUT | |
| - name: Checkout Timer (SurfTimer.Plugin) repo | |
| uses: actions/checkout@v4 | |
| with: | |
| # In this workflow the file is in the Timer repo | |
| ref: ${{ env.RELEASE_TAG }} | |
| path: Timer | |
| - name: Checkout SurfTimer.Shared | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: tslashd/SurfTimer.Shared | |
| path: SurfTimer.Shared | |
| # If the repo is private: | |
| # token: ${{ secrets.SHARED_REPO_PAT }} | |
| # Optionally pin a version: | |
| # ref: v1.2.3 | |
| - name: Setup .NET 8 | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: 8.0.x | |
| - name: Restore (Shared + Plugin) | |
| shell: bash | |
| run: | | |
| dotnet restore "SurfTimer.Shared/SurfTimer.Shared.csproj" | |
| # Find .csproj of the plugin automatically | |
| PLUGIN_CSPROJ="$(cd Timer && git ls-files '**/SurfTimer.Plugin.csproj' | head -n1)" | |
| if [ -z "$PLUGIN_CSPROJ" ]; then | |
| echo "SurfTimer.Plugin.csproj not found in Timer repo" | |
| exit 1 | |
| fi | |
| echo "PLUGIN_CSPROJ=Timer/$PLUGIN_CSPROJ" >> $GITHUB_ENV | |
| dotnet restore "$PLUGIN_CSPROJ" | |
| - name: Build SurfTimer.Shared | |
| run: dotnet build SurfTimer.Shared/SurfTimer.Shared.csproj -c Release --no-restore | |
| - name: Build & Publish SurfTimer.Plugin | |
| env: | |
| OUT_DIR: out/publish | |
| shell: bash | |
| run: | | |
| # Publish aclass library, to copy dependencies to out/publish | |
| dotnet publish "$PLUGIN_CSPROJ" \ | |
| -c Release \ | |
| -o "$OUT_DIR" \ | |
| /p:CopyLocalLockFileAssemblies=true \ | |
| /p:IncludeBuildOutput=true \ | |
| /p:PublishSingleFile=false \ | |
| /p:PublishTrimmed=false | |
| echo "Publish output:" | |
| ls -la "$OUT_DIR" | |
| - name: Prepare package layout | |
| env: | |
| OUT_DIR: out/publish | |
| PKG_ROOT: package | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| # Paths | |
| ADDONS_DIR="$PKG_ROOT/addons/SurfTimer.Plugin" | |
| CFG_DST="$PKG_ROOT/cfg" | |
| mkdir -p "$ADDONS_DIR" "$ADDONS_DIR/data/GeoIP" "$ADDONS_DIR/lang" "$CFG_DST" | |
| # Copy main DLLs from publish | |
| cp -v "$OUT_DIR/SurfTimer.Plugin.dll" "$ADDONS_DIR/" | |
| # Copy SurfTimer.Shared.dll from the built Shared | |
| SHARED_DLL="SurfTimer.Shared/bin/Release/net8.0/SurfTimer.Shared.dll" | |
| test -f "$SHARED_DLL" || { echo "Missing $SHARED_DLL"; exit 1; } | |
| cp -v "$SHARED_DLL" "$ADDONS_DIR/" | |
| # Copy dependencies (try from publish; if missing, fallback from Timer/src/bin) | |
| need() { test -f "$1" || { echo "Missing $1"; exit 1; }; } | |
| copy_dep() { | |
| local NAME="$1" | |
| if [ -f "$OUT_DIR/$NAME" ]; then | |
| cp -v "$OUT_DIR/$NAME" "$ADDONS_DIR/" | |
| elif [ -f "Timer/src/bin/$NAME" ]; then | |
| cp -v "Timer/src/bin/$NAME" "$ADDONS_DIR/" | |
| else | |
| echo "Dependency $NAME not found in publish or Timer/src/bin" | |
| exit 1 | |
| fi | |
| } | |
| copy_dep "Dapper.dll" | |
| copy_dep "MaxMind.Db.dll" | |
| copy_dep "MaxMind.GeoIP2.dll" | |
| copy_dep "MySqlConnector.dll" | |
| # Copy data and lang | |
| need "Timer/data/GeoIP/GeoLite2-Country.mmdb" | |
| cp -v "Timer/data/GeoIP/GeoLite2-Country.mmdb" "$ADDONS_DIR/data/GeoIP/" | |
| need "Timer/lang/en.json" | |
| cp -v "Timer/lang/en.json" "$ADDONS_DIR/lang/" | |
| # Copy the whole cfg/ folder | |
| if [ -d "Timer/cfg" ]; then | |
| cp -av "Timer/cfg/." "$CFG_DST/" | |
| else | |
| echo "Timer/cfg not found" | |
| exit 1 | |
| fi | |
| echo "Final package tree:" | |
| tree -a "$PKG_ROOT" || true | |
| - name: Zip & checksum | |
| env: | |
| PKG_ROOT: package | |
| shell: bash | |
| run: | | |
| ZIP="SurfTimer.Plugin-${RELEASE_TAG}.zip" | |
| (cd "$PKG_ROOT" && zip -r "../$ZIP" .) | |
| sha256sum "$ZIP" > "$ZIP.sha256" | |
| echo "Built $ZIP and $ZIP.sha256" | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: SurfTimer.Plugin-${{ env.RELEASE_TAG }} | |
| path: | | |
| SurfTimer.Plugin-${{ env.RELEASE_TAG }}.zip | |
| SurfTimer.Plugin-${{ env.RELEASE_TAG }}.zip.sha256 | |
| release: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - name: Determine tag | |
| id: vars | |
| shell: bash | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| TAG="${{ github.event.inputs.tag }}" | |
| else | |
| TAG="${{ github.ref_name }}" | |
| fi | |
| echo "tag=$TAG" >> $GITHUB_OUTPUT | |
| echo "RELEASE_TAG=$TAG" >> $GITHUB_ENV | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: ./artifacts | |
| - name: List artifacts | |
| run: ls -R ./artifacts | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.vars.outputs.tag }} | |
| name: SurfTimer.Plugin ${{ steps.vars.outputs.tag }} | |
| draft: false | |
| prerelease: ${{ contains(steps.vars.outputs.tag, '-rc') || contains(steps.vars.outputs.tag, '-beta') || contains(steps.vars.outputs.tag, '-alpha') }} | |
| files: | | |
| artifacts/SurfTimer.Plugin-${{ env.RELEASE_TAG }}/SurfTimer.Plugin-${{ env.RELEASE_TAG }}.zip | |
| artifacts/SurfTimer.Plugin-${{ env.RELEASE_TAG }}/SurfTimer.Plugin-${{ env.RELEASE_TAG }}.zip.sha256 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |