Merge pull request #9 from henry-js/develop #23
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: Build Pre-release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| jobs: | |
| check-config: | |
| name: Check Project Configuration | |
| runs-on: ubuntu-latest | |
| outputs: | |
| is_library: ${{ steps.check_file.outputs.is_library }} | |
| is_app: ${{ steps.check_file.outputs.is_app }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: cat public.env | |
| run: cat public.env | |
| - name: Read configuration from public.env | |
| id: check_file | |
| run: | | |
| IS_LIBRARY="false" | |
| IS_APP="false" | |
| while IFS= read -r line || [[ -n "$line" ]]; do | |
| case "$line" in | |
| PROJECT_TO_PACK=*) | |
| value="${line#*=}" | |
| if [[ -n "$value" ]]; then IS_LIBRARY="true"; fi | |
| ;; | |
| PROJECT_TO_PUBLISH=*) | |
| value="${line#*=}" | |
| if [[ -n "$value" ]]; then IS_APP="true"; fi | |
| ;; | |
| esac | |
| done < public.env | |
| echo "is_library=${IS_LIBRARY}" >> $GITHUB_OUTPUT | |
| echo "is_app=${IS_APP}" >> $GITHUB_OUTPUT | |
| build-library: | |
| name: Build NuGet Pre-release | |
| needs: check-config | |
| if: needs.check-config.outputs.is_library == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: { fetch-depth: 0 } | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| - name: Setup Taskfile | |
| uses: arduino/setup-task@v2 | |
| with: | |
| repo-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Get pre-release version and set ENV | |
| run: echo "APP_VERSION=$(task get-version)" >> $GITHUB_ENV | |
| - name: Run Tests | |
| run: task test | |
| - name: Pack NuGet Pre-release Package | |
| run: task pack-nuget | |
| - name: Upload NuGet Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: nuget-artifact-${{ env.APP_VERSION }} | |
| path: dist/nuget/ | |
| build-application: | |
| name: Build App for ${{ matrix.os }}-${{ matrix.arch }} | |
| needs: check-config | |
| if: needs.check-config.outputs.is_app == 'true' | |
| runs-on: ${{ matrix.runner_os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - { runner_os: windows-latest, os: win, arch: x64 } | |
| - { runner_os: ubuntu-latest, os: linux, arch: x64 } | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: { fetch-depth: 0 } | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| - name: Setup Taskfile | |
| uses: arduino/setup-task@v2 | |
| with: | |
| repo-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Add .NET tools to PATH | |
| if: runner.os != 'Windows' | |
| run: echo "$HOME/.dotnet/tools" >> $GITHUB_PATH | |
| - name: Get pre-release version and set ENV | |
| id: version # Keep the id for the artifact name | |
| shell: bash # Use bash for consistency on all runners | |
| run: | | |
| # 1. Capture the output | |
| VERSION_OUTPUT=$(task get-version) | |
| # 2. Validate the output | |
| if [ -z "$VERSION_OUTPUT" ]; then | |
| echo "::error::'task get-version' failed or produced an empty string." | |
| exit 1 | |
| fi | |
| # 3. If validation passes, set the environment and output variables | |
| echo "Discovered version: ${VERSION_OUTPUT}" | |
| echo "APP_VERSION=${VERSION_OUTPUT}" >> $GITHUB_ENV | |
| echo "version=${VERSION_OUTPUT}" >> $GITHUB_OUTPUT | |
| - name: Run Tests | |
| run: task test | |
| - name: Build and Pack Pre-release for ${{ matrix.os }}-${{ matrix.arch }} | |
| run: task build-platform-release OS=${{ matrix.os }} ARCH=${{ matrix.arch }} APP_VERSION=${{ env.APP_VERSION }} | |
| - name: Upload Application Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: app-artifact-${{ matrix.os }}-${{ matrix.arch }}-${{ env.APP_VERSION }} | |
| path: dist/releases/ |