From b77bb0d504c2c0e579e8e74fcdbde26aa6e45ed8 Mon Sep 17 00:00:00 2001 From: Rajendra Singh <14791461+SinghRajenM@users.noreply.github.com> Date: Sat, 2 Nov 2024 20:43:54 +0530 Subject: [PATCH] Improve build workflow (#206) * Improve build workflow * Upload full artifacts * Run unit test for both debug and release for x86 and x64 * Relace hardcoded values with variable * Try similifying consolidated artfact upload #fixes #205, #closes #205 --- .github/workflows/ci_build.yml | 101 ++++++++++++++++++++------------- 1 file changed, 60 insertions(+), 41 deletions(-) diff --git a/.github/workflows/ci_build.yml b/.github/workflows/ci_build.yml index f40bdec..38051e8 100644 --- a/.github/workflows/ci_build.yml +++ b/.github/workflows/ci_build.yml @@ -1,4 +1,4 @@ -name: Build and test +name: Build and Test on: push: @@ -6,9 +6,13 @@ on: pull_request: branches: [ "master" ] +env: + BUILD_DIR: src\Build\Bin + MSBUILD_TOOLSET: v143 + ARTIFACT_PREFIX: NppJSONViewer_ + jobs: build: - runs-on: windows-latest strategy: fail-fast: false @@ -17,45 +21,60 @@ jobs: build_platform: [Win32, x64, ARM64] steps: - # Step 1: Check out the code from the repo - - name: Checkout repo - uses: actions/checkout@v4 - with: + # Step 1: Check out the code from the repo + - name: Checkout repo + uses: actions/checkout@v4 + with: submodules: recursive - # Step 2: Prepare for build - - name: Pre Build - uses: microsoft/setup-msbuild@v2 + # Step 2: Prepare for build + - name: Setup MSBuild + uses: microsoft/setup-msbuild@v2 - # Step 3: Build projects and unit test - - name: Build - working-directory: src - run: msbuild NppJSONViewer.sln /m /p:configuration="${{ matrix.build_configuration }}" /p:platform="${{ matrix.build_platform }}" /p:PlatformToolset="v143" - - # Step 4: Upload build binary artifacts - - name: Archive binaries artifacts - uses: actions/upload-artifact@v4 - with: - name: ${{ matrix.build_platform}}_${{ matrix.build_configuration}} - path: src\Build\Bin\${{ matrix.build_configuration}}\${{ matrix.build_platform}}\NPPJSONViewer.dll - - # Step 5: Upload build pdb artifacts - - name: Archive symbols artifacts - uses: actions/upload-artifact@v4 - with: - name: ${{ matrix.build_platform}}_${{ matrix.build_configuration}}_pdb - path: src\Build\Bin\${{ matrix.build_configuration}}\${{ matrix.build_platform}}\NPPJSONViewer.pdb - - # Step 6: Run unit tests for x86 | Release - - name: Run tests x86 | Release - if: matrix.build_platform == 'Win32' && matrix.build_configuration == 'Release' - run: | - cd src\Build\Bin\Release\Win32 - ./UnitTest.exe - - # Step 7: Run unit tests for x64 | Release - - name: Run tests x64 | Release - if: matrix.build_platform == 'x64' && matrix.build_configuration == 'Release' - run: | - cd src\Build\Bin\Release\x64 - ./UnitTest.exe + # Step 3: Build projects and unit test + - name: Build code + working-directory: src + run: msbuild NppJSONViewer.sln /m /p:configuration="${{matrix.build_configuration}}" /p:platform="${{matrix.build_platform}}" /p:PlatformToolset=${{env.MSBUILD_TOOLSET}} + + # Step 4: Upload build binary artifacts for deployment + - name: Archive binaries artifacts + uses: actions/upload-artifact@v4 + with: + name: ${{env.ARTIFACT_PREFIX}}${{matrix.build_platform}}_${{matrix.build_configuration}} + path: ${{env.BUILD_DIR }}\${{matrix.build_configuration}}\${{matrix.build_platform}}\NPPJSONViewer.dll + + # Step 5: Upload build pdb artifacts + - name: Archive symbols artifacts + uses: actions/upload-artifact@v4 + with: + name: ${{env.ARTIFACT_PREFIX}}${{matrix.build_platform}}_${{matrix.build_configuration}}_pdb + path: ${{env.BUILD_DIR }}\${{matrix.build_configuration}}\${{matrix.build_platform}}\NPPJSONViewer.pdb + + # Step 6: Run unit tests for x86 and x64 + - name: Run unit tests + if: matrix.build_platform == 'Win32' || matrix.build_platform == 'x64' + run: | + cd ${{env.BUILD_DIR}}\${{matrix.build_configuration}}\${{matrix.build_platform}} + ./UnitTest.exe + + upload-full-artifacts: + # Trigger this job only after all 'build' jobs are complete + needs: build + runs-on: windows-latest + strategy: + fail-fast: true + + steps: + # Step 7: Download all artifacts from the build job + - name: Download all artifacts + uses: actions/download-artifact@v4 + with: + pattern: ${{env.ARTIFACT_PREFIX}}* + path: all_artifacts\ + + # Step 8: Upload consolidated artifacts as a single artifact + - name: Upload full artifact + uses: actions/upload-artifact@v4 + with: + name: ${{env.ARTIFACT_PREFIX}}ALL + path: all_artifacts\**