|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + bump: |
| 9 | + description: "Version bump type" |
| 10 | + required: false |
| 11 | + default: "patch" |
| 12 | + type: choice |
| 13 | + options: |
| 14 | + - patch |
| 15 | + - minor |
| 16 | + - major |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: write |
| 20 | + |
| 21 | +env: |
| 22 | + DOTNET_VERSION: "9.x.x" |
| 23 | + SOLUTION_DIR: "VisualPairCoding" |
| 24 | + PROJECT: "./VisualPairCoding.AvaloniaUI/VisualPairCoding.AvaloniaUI.csproj" |
| 25 | + |
| 26 | +jobs: |
| 27 | + prepare: |
| 28 | + name: Prepare Release |
| 29 | + runs-on: ubuntu-latest |
| 30 | + outputs: |
| 31 | + version: ${{ steps.version.outputs.version }} |
| 32 | + tag: ${{ steps.version.outputs.tag }} |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v4 |
| 35 | + with: |
| 36 | + fetch-depth: 0 |
| 37 | + fetch-tags: true |
| 38 | + |
| 39 | + - name: Calculate next version |
| 40 | + id: version |
| 41 | + run: | |
| 42 | + # Determine bump type |
| 43 | + BUMP="${{ github.event.inputs.bump || 'patch' }}" |
| 44 | + echo "Bump type: $BUMP" |
| 45 | +
|
| 46 | + # Find latest semver tag (supports v1.78 as v1.78.0) |
| 47 | + LATEST_TAG=$(git tag --list 'v[0-9]*' --sort=-version:refname | head -n1) |
| 48 | + echo "Latest tag: $LATEST_TAG" |
| 49 | +
|
| 50 | + if [ -z "$LATEST_TAG" ]; then |
| 51 | + MAJOR=1; MINOR=0; PATCH=0 |
| 52 | + else |
| 53 | + # Strip 'v' prefix |
| 54 | + VERSION="${LATEST_TAG#v}" |
| 55 | + # Handle two-part versions (v1.78 -> 1.78.0) |
| 56 | + IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION" |
| 57 | + PATCH="${PATCH:-0}" |
| 58 | + fi |
| 59 | +
|
| 60 | + echo "Current: $MAJOR.$MINOR.$PATCH" |
| 61 | +
|
| 62 | + case "$BUMP" in |
| 63 | + major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;; |
| 64 | + minor) MINOR=$((MINOR + 1)); PATCH=0 ;; |
| 65 | + patch) PATCH=$((PATCH + 1)) ;; |
| 66 | + esac |
| 67 | +
|
| 68 | + NEW_VERSION="$MAJOR.$MINOR.$PATCH" |
| 69 | + NEW_TAG="v$NEW_VERSION" |
| 70 | + echo "Next version: $NEW_VERSION (tag: $NEW_TAG)" |
| 71 | +
|
| 72 | + echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT |
| 73 | + echo "tag=$NEW_TAG" >> $GITHUB_OUTPUT |
| 74 | +
|
| 75 | + build-and-release: |
| 76 | + name: Build ${{ matrix.OUTPUTDIR }} |
| 77 | + needs: prepare |
| 78 | + runs-on: ${{ matrix.os }} |
| 79 | + strategy: |
| 80 | + fail-fast: false |
| 81 | + matrix: |
| 82 | + os: [windows-latest, ubuntu-latest, macos-latest] |
| 83 | + include: |
| 84 | + - os: windows-latest |
| 85 | + RUNTIMEID: win-x64 |
| 86 | + OUTPUTDIR: VisualPairCoding-win-x64 |
| 87 | + - os: ubuntu-latest |
| 88 | + RUNTIMEID: linux-x64 |
| 89 | + OUTPUTDIR: VisualPairCoding-linux-x64 |
| 90 | + - os: macos-latest |
| 91 | + RUNTIMEID: osx-x64 |
| 92 | + OUTPUTDIR: VisualPairCoding-osx-x64 |
| 93 | + |
| 94 | + steps: |
| 95 | + - uses: actions/checkout@v4 |
| 96 | + |
| 97 | + - name: Setup .NET |
| 98 | + uses: actions/setup-dotnet@v4 |
| 99 | + with: |
| 100 | + dotnet-version: ${{ env.DOTNET_VERSION }} |
| 101 | + |
| 102 | + - name: Cache NuGet packages |
| 103 | + uses: actions/cache@v4 |
| 104 | + with: |
| 105 | + path: ~/.nuget/packages |
| 106 | + key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} |
| 107 | + restore-keys: ${{ runner.os }}-nuget- |
| 108 | + |
| 109 | + - name: Install dependencies |
| 110 | + run: dotnet restore |
| 111 | + working-directory: Source/${{ env.SOLUTION_DIR }} |
| 112 | + |
| 113 | + - name: Set version number |
| 114 | + run: ./Set-Version-Number.ps1 "${{ needs.prepare.outputs.tag }}" |
| 115 | + working-directory: Scripts |
| 116 | + shell: pwsh |
| 117 | + |
| 118 | + - name: Build |
| 119 | + run: dotnet build --configuration Release --no-restore |
| 120 | + working-directory: Source/${{ env.SOLUTION_DIR }} |
| 121 | + |
| 122 | + - name: Test |
| 123 | + run: dotnet test --no-build --configuration Release |
| 124 | + working-directory: Source/${{ env.SOLUTION_DIR }} |
| 125 | + |
| 126 | + - name: Publish |
| 127 | + run: > |
| 128 | + dotnet publish ${{ env.PROJECT }} |
| 129 | + -c Release |
| 130 | + -o ${{ matrix.OUTPUTDIR }} |
| 131 | + -p:PublishReadyToRun=true |
| 132 | + --self-contained true |
| 133 | + -p:PublishSingleFile=true |
| 134 | + -p:IncludeNativeLibrariesForSelfExtract=true |
| 135 | + -p:UseAppHost=true |
| 136 | + -r ${{ matrix.RUNTIMEID }} |
| 137 | + working-directory: Source/${{ env.SOLUTION_DIR }} |
| 138 | + |
| 139 | + - uses: vimtor/action-zip@v1 |
| 140 | + with: |
| 141 | + files: ./Source/${{ env.SOLUTION_DIR }}/${{ matrix.OUTPUTDIR }}/ |
| 142 | + dest: ${{ matrix.OUTPUTDIR }}.zip |
| 143 | + |
| 144 | + - name: Upload artifact |
| 145 | + uses: actions/upload-artifact@v4 |
| 146 | + with: |
| 147 | + name: ${{ matrix.OUTPUTDIR }} |
| 148 | + path: ${{ matrix.OUTPUTDIR }}.zip |
| 149 | + |
| 150 | + create-release: |
| 151 | + name: Create Release |
| 152 | + needs: [prepare, build-and-release] |
| 153 | + runs-on: ubuntu-latest |
| 154 | + steps: |
| 155 | + - uses: actions/checkout@v4 |
| 156 | + |
| 157 | + - name: Download all artifacts |
| 158 | + uses: actions/download-artifact@v4 |
| 159 | + with: |
| 160 | + path: artifacts |
| 161 | + |
| 162 | + - name: Create tag and release |
| 163 | + env: |
| 164 | + GH_TOKEN: ${{ github.token }} |
| 165 | + run: | |
| 166 | + TAG="${{ needs.prepare.outputs.tag }}" |
| 167 | + VERSION="${{ needs.prepare.outputs.version }}" |
| 168 | +
|
| 169 | + # Create tag |
| 170 | + git tag "$TAG" |
| 171 | + git push origin "$TAG" |
| 172 | +
|
| 173 | + # Collect all zip files |
| 174 | + find artifacts -name '*.zip' -exec mv {} . \; |
| 175 | +
|
| 176 | + # Create release |
| 177 | + gh release create "$TAG" \ |
| 178 | + --title "VisualPairCoding $VERSION" \ |
| 179 | + --generate-notes \ |
| 180 | + *.zip |
0 commit comments