Skip to content

chore: always compress to tar.gz #15

chore: always compress to tar.gz

chore: always compress to tar.gz #15

Workflow file for this run

name: Continuous Integration
on:
push:
branches:
- main
tags:
- "v*"
pull_request:
branches:
- main
# Add permissions for creating releases
permissions:
contents: write
packages: write
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
jobs:
build-and-test:
runs-on: ubuntu-latest
strategy:
matrix:
configuration:
- Release
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: Restore dependencies
run: dotnet restore --verbosity minimal
- name: Build solution
run: dotnet build --configuration ${{ matrix.configuration }} --no-restore --verbosity minimal
- name: Run tests
run: dotnet test --configuration ${{ matrix.configuration }} --no-build --verbosity minimal --logger trx --results-directory ./artifacts/test-results
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results-${{ matrix.configuration }}
path: ./artifacts/test-results/*.trx
build-cross-platform:
needs: build-and-test
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
runs-on: ubuntu-latest
strategy:
matrix:
runtime:
- linux-x64
- linux-arm64
- win-x64
- win-arm64
- osx-x64
- osx-arm64
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: Generate version
id: version
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
# For tags, use the tag name as version
VERSION=${GITHUB_REF#refs/tags/v}
ASSEMBLY_VERSION="${VERSION}.0"
FILE_VERSION="${VERSION}.0"
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "assembly_version=${ASSEMBLY_VERSION}" >> $GITHUB_OUTPUT
echo "file_version=${FILE_VERSION}" >> $GITHUB_OUTPUT
echo "is_release=true" >> $GITHUB_OUTPUT
else
# For main branch, generate preview version
BASE_VERSION=$(awk -F'[<>]' '/<PackageVersion>/{print $3}' src/Nuggy.Cli.csproj)
TIMESTAMP=$(date -u +%Y%m%d%H%M%S)
VERSION="${BASE_VERSION}-preview.${TIMESTAMP}"
ASSEMBLY_VERSION="${BASE_VERSION}.0"
FILE_VERSION="${BASE_VERSION}.0"
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "assembly_version=${ASSEMBLY_VERSION}" >> $GITHUB_OUTPUT
echo "file_version=${FILE_VERSION}" >> $GITHUB_OUTPUT
echo "is_release=false" >> $GITHUB_OUTPUT
fi
echo "Generated version: ${VERSION}"
- name: Publish single-file executable
run: |
echo "Publishing for runtime: ${{ matrix.runtime }}"
echo "Version: ${{ steps.version.outputs.version }}"
dotnet publish src/Nuggy.Cli.csproj \
--configuration Release \
--runtime ${{ matrix.runtime }} \
--self-contained true \
--output ./artifacts/publish/${{ matrix.runtime }} \
-p:PublishSingleFile=true \
-p:PublishTrimmed=true \
-p:TrimMode=link \
-p:EnableCompressionInSingleFile=true \
-p:IncludeNativeLibrariesForSelfExtract=true \
-p:AssemblyVersion=${{ steps.version.outputs.assembly_version }} \
-p:FileVersion=${{ steps.version.outputs.file_version }} \
-p:Version=${{ steps.version.outputs.version }}
- name: Debug published files
run: |
echo "Published files for ${{ matrix.runtime }}:"
ls -la ./artifacts/publish/${{ matrix.runtime }}/
- name: Create archive
run: |
echo "Creating archive for ${{ matrix.runtime }}..."
echo "Source directory: ./artifacts/publish/${{ matrix.runtime }}/"
echo "Files to archive:"
ls -la ./artifacts/publish/${{ matrix.runtime }}/
# Always create tar.gz archives regardless of platform (Linux runner has tar available)
ARCHIVE_PATH="./artifacts/nuggy-${{ steps.version.outputs.version }}-${{ matrix.runtime }}.tar.gz"
echo "Creating tar.gz archive: $ARCHIVE_PATH"
tar -czf "$ARCHIVE_PATH" -C "./artifacts/publish/${{ matrix.runtime }}" .
echo "Created tar.gz archive"
- name: Verify archive creation
run: |
echo "Verifying archive was created..."
echo "Current working directory: $(pwd)"
echo "Looking for archive files..."
# Always expect tar.gz files now
ARCHIVE_FILE="./artifacts/nuggy-${{ steps.version.outputs.version }}-${{ matrix.runtime }}.tar.gz"
if [ -f "$ARCHIVE_FILE" ]; then
echo "✅ Archive found: $ARCHIVE_FILE"
ls -la "$ARCHIVE_FILE"
else
echo "❌ Archive not found: $ARCHIVE_FILE"
echo "Files in artifacts directory:"
ls -la ./artifacts/
exit 1
fi
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: nuggy-${{ matrix.runtime }}
path: ./artifacts/nuggy-${{ steps.version.outputs.version }}-${{ matrix.runtime }}.tar.gz
if-no-files-found: error
create-release:
# Create GitHub releases for both tagged releases and preview releases from main
# Tagged releases (v1.0.0) -> stable releases
# Main branch pushes -> preview releases with timestamp versions
needs: build-cross-platform
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get version
id: version
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
# For tags, use the tag name as version
VERSION=${GITHUB_REF#refs/tags/v}
IS_PRERELEASE=false
RELEASE_NAME="Release $VERSION"
else
# For main branch, generate preview version
BASE_VERSION=$(awk -F'[<>]' '/<PackageVersion>/{print $3}' src/Nuggy.Cli.csproj)
TIMESTAMP=$(date -u +%Y%m%d%H%M%S)
VERSION="${BASE_VERSION}-preview.${TIMESTAMP}"
IS_PRERELEASE=true
RELEASE_NAME="Preview Release $VERSION"
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "is_prerelease=${IS_PRERELEASE}" >> $GITHUB_OUTPUT
echo "release_name=${RELEASE_NAME}" >> $GITHUB_OUTPUT
echo "Generated version: ${VERSION}"
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
- name: List downloaded artifacts for debugging
run: |
echo "Downloaded artifacts structure:"
find ./artifacts -type f -name "*.tar.gz" | sort
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.version.outputs.version }}
name: ${{ steps.version.outputs.release_name }}
body: |
## ${{ steps.version.outputs.release_name }}
### Downloads
Choose the appropriate binary for your platform (all archives are in tar.gz format):
- **Linux x64**: `nuggy-${{ steps.version.outputs.version }}-linux-x64.tar.gz`
- **Linux ARM64**: `nuggy-${{ steps.version.outputs.version }}-linux-arm64.tar.gz`
- **Windows x64**: `nuggy-${{ steps.version.outputs.version }}-win-x64.tar.gz`
- **Windows ARM64**: `nuggy-${{ steps.version.outputs.version }}-win-arm64.tar.gz`
- **macOS x64**: `nuggy-${{ steps.version.outputs.version }}-osx-x64.tar.gz`
- **macOS ARM64**: `nuggy-${{ steps.version.outputs.version }}-osx-arm64.tar.gz`
### Installation
1. Download the appropriate archive for your platform
2. Extract the archive: `tar -xzf nuggy-*.tar.gz`
3. Run the `nuggy` executable (or `Nuggy.Cli.exe` on Windows)
### Alternatively, install as a .NET tool
```bash
dotnet tool install -g Nuggy.Cli
```
${{ steps.version.outputs.is_prerelease == 'true' && '> **Note**: This is a preview release built from the latest main branch. Use at your own risk.' || '' }}
files: "./artifacts/nuggy-*/nuggy-${{ steps.version.outputs.version }}-*.tar.gz"
draft: false
prerelease: ${{ steps.version.outputs.is_prerelease }}
token: ${{ secrets.GITHUB_TOKEN }}
publish-nuget:
needs: build-and-test
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: Generate version
id: version
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
# For tags, use the tag name as version
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "is_release=true" >> $GITHUB_OUTPUT
else
# For main branch, generate preview version
BASE_VERSION=$(awk -F'[<>]' '/<PackageVersion>/{print $3}' src/Nuggy.Cli.csproj)
TIMESTAMP=$(date -u +%Y%m%d%H%M%S)
VERSION="${BASE_VERSION}-preview.${TIMESTAMP}"
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "is_release=false" >> $GITHUB_OUTPUT
fi
echo "Generated version: ${VERSION}"
- name: Pack NuGet package
run: |
dotnet pack src/Nuggy.Cli.csproj \
--configuration Release \
--output ./artifacts/packages \
-p:PackageVersion=${{ steps.version.outputs.version }}
- name: Publish to NuGet.org
run: |
dotnet nuget push ./artifacts/packages/*.nupkg \
--source https://api.nuget.org/v3/index.json \
--api-key ${{ secrets.NUGET_API_KEY }} \
--skip-duplicate
- name: Upload NuGet package
uses: actions/upload-artifact@v4
with:
name: nuget-package
path: ./artifacts/packages/*.nupkg