Try a simple approach to releasing proper version in templates #187
Workflow file for this run
This file contains 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
# This workflow will build a .NET project | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net | |
name: Build | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
workflow_call: | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
name: Build on ${{ matrix.os }} with Dotnet ${{ matrix.dotnet }} | |
strategy: | |
matrix: | |
dotnet: [ '10.x'] | |
os: [ubuntu-latest, windows-latest] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: ${{ matrix.dotnet }} | |
- name: Restore dependencies | |
run: dotnet restore | |
- name: Prepare WASM SDKs | |
run: dotnet msbuild src/WitBindgen/build/BytecodeAlliance.Componentize.DotNet.WitBindgen.targets /t:PrepareWasmSdks | |
- name: Build | |
run: dotnet build --no-restore /p:BuildNumber=${{ github.run_number }} | |
- name: Test | |
run: dotnet test --no-build --verbosity normal | |
- name: Pack | |
run: dotnet pack -c Release /p:BuildNumber=${{ github.run_number }} | |
- name: Ensure package and template versions match | |
shell: bash | |
run: | | |
ls ./artifacts/*.nupkg | |
version=$(unzip -p ./artifacts/*SDK*.nupkg '*.nuspec' | grep -oPm1 "(?<=<version>)[^<]+" | grep -oE "^[0-9]+\.[0-9]+\.[0-9]+-preview") | |
template_version=$(grep -oPm1 "(?<=Version=\")[^\"]+" ./templates/content/wasi-cli/wasi-cli.csproj | grep -oE "^[0-9]+\.[0-9]+\.[0-9]+-preview") | |
echo "Package Version: $version | Template version: $template_version" | |
if [ "$version" != "$template_version" ]; then | |
echo "Version mismatch: Package version ($version) does not match template version ($template_version)"; | |
exit 1; | |
fi | |
- name: Test Template | |
shell: bash | |
run: | | |
artifact_dir=${{ github.workspace }}/artifacts | |
dotnet new install ./artifacts/BytecodeAlliance.Componentize.DotNet.Templates.*.nupkg | |
mkdir ${{ runner.temp }}/projects | |
pushd ${{ runner.temp }}/projects | |
dotnet new componentize.wasi.cli -o test | |
cd test | |
dotnet nuget add source $artifact_dir | |
dotnet build | |
dotnet list package | |
popd | |
# must use windows to generate package https://github.com/bytecodealliance/componentize-dotnet/issues/41 | |
# only need one package published https://github.com/actions/upload-artifact?tab=readme-ov-file#not-uploading-to-the-same-artifact | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: nuget-packages | |
path: artifacts/*.nupkg | |
if-no-files-found: error | |
if: ${{ matrix.dotnet == '10.x' && matrix.os == 'windows-latest' }} | |