|
| 1 | +name: Build SMAPI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "[0-9]+.[0-9]+.[0-9]+" # stable version tag |
| 7 | + branches: |
| 8 | + - develop |
| 9 | + - build-test |
| 10 | + |
| 11 | +jobs: |
| 12 | + build_and_release: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + permissions: |
| 15 | + contents: write # for creating releases |
| 16 | + id-token: write # for creating attestations |
| 17 | + attestations: write |
| 18 | + steps: |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 |
| 23 | + |
| 24 | + - name: Get SMAPI assembly version |
| 25 | + id: smapi-version |
| 26 | + shell: pwsh |
| 27 | + run: | |
| 28 | + [xml]$xml = Get-Content build/common.targets |
| 29 | + [string]$version = $xml.Project.PropertyGroup.Version |
| 30 | + $version = $version.Trim() |
| 31 | +
|
| 32 | + $pattern = '^(\d+)\.(\d+)\.(\d+)$' |
| 33 | + if ($version -match $pattern) { |
| 34 | + $major = $Matches[1] |
| 35 | + $minor = $Matches[2] |
| 36 | + $patch = $Matches[3] |
| 37 | + } |
| 38 | + else { |
| 39 | + Write-Error "The version '$version' found in build/common.targets did not match the strict x.y.z format. Aborting." |
| 40 | + Write-Host 'Debug info:' |
| 41 | + Write-Host "Extracted version: $version" |
| 42 | + exit 1 |
| 43 | + } |
| 44 | +
|
| 45 | + "smapi_version=$version" | Out-File $env:GITHUB_OUTPUT -Append |
| 46 | + "smapi_major=$major" | Out-File $env:GITHUB_OUTPUT -Append |
| 47 | + "smapi_minor=$minor" | Out-File $env:GITHUB_OUTPUT -Append |
| 48 | + "smapi_patch=$patch" | Out-File $env:GITHUB_OUTPUT -Append |
| 49 | + "VERSION=$major.$minor.$patch" | Out-File $env:GITHUB_ENV -Append |
| 50 | +
|
| 51 | + Write-Host "Version: $major.$minor.$patch" |
| 52 | +
|
| 53 | + - name: Verify SMAPI assembly version matches tag |
| 54 | + if: github.ref_type == 'tag' |
| 55 | + shell: pwsh |
| 56 | + run: | |
| 57 | + if ($env:VERSION -ne '${{github.ref_name}}') { |
| 58 | + Write-Error "The pushed tag '${{github.ref_name}}' doesn't match the version '$env:VERSION' found in build/common.targets. Aborting." |
| 59 | + Write-Host 'Debug info:' |
| 60 | + Write-Host 'Tag: ${{github.ref_name}}' |
| 61 | + Write-Host "In common.targets: $env:VERSION" |
| 62 | + exit 1 |
| 63 | + } |
| 64 | +
|
| 65 | + - name: Update SMAPI assembly version |
| 66 | + if: github.ref_type != 'tag' |
| 67 | + shell: pwsh |
| 68 | + run: | |
| 69 | + $updatedPatch = [int]${{steps.smapi-version.outputs.smapi_patch}} + 1 |
| 70 | + $timestamp = Get-Date -Format 'yyyyMMdd-HHmm' |
| 71 | + $updatedVersion = "${{steps.smapi-version.outputs.smapi_major}}.${{steps.smapi-version.outputs.smapi_minor}}.$updatedPatch-alpha.$timestamp" |
| 72 | +
|
| 73 | + "VERSION=$updatedVersion" | Out-File $env:GITHUB_ENV -Append |
| 74 | +
|
| 75 | + Write-Host "This is a dev version. Building as version: $updatedVersion" |
| 76 | +
|
| 77 | + ./build/scripts/set-smapi-version.ps1 "$updatedVersion" |
| 78 | + Write-Host 'Version updated.' |
| 79 | +
|
| 80 | + - name: Checkout game reference assemblies |
| 81 | + run: | |
| 82 | + git clone --depth 1 https://github.com/StardewModders/mod-reference-assemblies.git "$HOME/StardewValley" |
| 83 | +
|
| 84 | + - name: Build SMAPI |
| 85 | + shell: pwsh |
| 86 | + run: | |
| 87 | + Write-Host "Building SMAPI $env:VERSION." |
| 88 | + ./build/scripts/prepare-install-package.ps1 "$env:VERSION" |
| 89 | +
|
| 90 | + - name: Upload installer |
| 91 | + uses: actions/upload-artifact@v4 |
| 92 | + with: |
| 93 | + name: 'SMAPI ${{env.VERSION}} installer' |
| 94 | + path: 'bin/SMAPI-${{env.VERSION}}-installer.zip' |
| 95 | + if-no-files-found: 'error' |
| 96 | + |
| 97 | + - name: Create GitHub release |
| 98 | + uses: ncipollo/release-action@v1 |
| 99 | + if: github.ref_type == 'tag' |
| 100 | + with: |
| 101 | + artifacts: 'bin/SMAPI-${{env.VERSION}}-installer.zip' |
| 102 | + token: '${{secrets.GITHUB_TOKEN}}' |
| 103 | + tag: '${{github.ref_name}}' |
| 104 | + name: '${{env.VERSION}}' |
| 105 | + body: | |
| 106 | + Draft. |
| 107 | + draft: true |
| 108 | + |
| 109 | + - name: Generate artifact attestations |
| 110 | + uses: actions/attest-build-provenance@v2 |
| 111 | + if: github.ref_type == 'tag' |
| 112 | + with: |
| 113 | + subject-path: bin/SMAPI-${{env.VERSION}}-installer.zip |
0 commit comments