From 7eb00d0f489e8461da8cc4ad891ebeef5daf7747 Mon Sep 17 00:00:00 2001 From: Sebastien Lebreton Date: Tue, 16 Apr 2024 10:09:49 +0200 Subject: [PATCH] Refactor CI to use Matrix Strategy (#322) --- .github/actions/setvars/action.yml | 13 ---- .github/variables/unity.env | 2 - .github/workflows/ci-linux.yml | 71 --------------------- .github/workflows/ci-macos.yml | 71 --------------------- .github/workflows/ci-matrix.yml | 99 ++++++++++++++++++++++++++++++ .github/workflows/ci-windows.yml | 77 ----------------------- README.md | 4 +- 7 files changed, 100 insertions(+), 237 deletions(-) delete mode 100644 .github/actions/setvars/action.yml delete mode 100644 .github/variables/unity.env delete mode 100644 .github/workflows/ci-linux.yml delete mode 100644 .github/workflows/ci-macos.yml create mode 100644 .github/workflows/ci-matrix.yml delete mode 100644 .github/workflows/ci-windows.yml diff --git a/.github/actions/setvars/action.yml b/.github/actions/setvars/action.yml deleted file mode 100644 index ee0cf98b..00000000 --- a/.github/actions/setvars/action.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: 'Set environment variables' -description: 'Configures environment variables for a workflow' -inputs: - varFilePath: - description: 'File path to variable file or directory. Defaults to ./.github/variables/* if none specified and runs against each file in that directory.' - required: false - default: ./.github/variables/* -runs: - using: "composite" - steps: - - run: | - sed "" ${{ inputs.varFilePath }} >> $GITHUB_ENV - shell: bash diff --git a/.github/variables/unity.env b/.github/variables/unity.env deleted file mode 100644 index e96f8d58..00000000 --- a/.github/variables/unity.env +++ /dev/null @@ -1,2 +0,0 @@ -UNITY_HASH=887be4894c44 -UNITY_FULL_VERSION=2022.3.22f1 \ No newline at end of file diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml deleted file mode 100644 index bb4c699d..00000000 --- a/.github/workflows/ci-linux.yml +++ /dev/null @@ -1,71 +0,0 @@ -name: CI-Linux - -on: - push: - branches: - - main - - release/* - pull_request: - branches: - - main - - release/* - -jobs: - linux: - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - deployments: read - packages: none - pull-requests: write - security-events: write - - steps: - - name: Checkout - uses: actions/checkout@v1 - - - name: Set Environment Variables - uses: ./.github/actions/setvars - with: - varFilePath: ./.github/variables/unity.env - - - name: Setup .NET - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '8.0.x' - include-prerelease: false - - - name: Download Unity - run: curl -o ./Unity.tar.xz -k https://download.unity3d.com/download_unity/${{ env.UNITY_HASH }}/LinuxEditorInstaller/Unity.tar.xz - - - name: Install Unity - run: mkdir -p ~/Unity && tar -xf Unity.tar.xz -C ~/Unity - - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - - - name: Build - run: dotnet build -c Debug ./src/Microsoft.Unity.Analyzers.sln /p:UseSharedCompilation=false - env: - DOTNET_CLI_TELEMETRY_OPTOUT: 1 - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 - DOTNET_NOLOGO: 1 - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 - - - name: Test context (main) - if: github.ref == 'refs/heads/main' - run: echo "TEST_FILTER=." >> $GITHUB_ENV - - - name: Test context (feature) - if: github.ref != 'refs/heads/main' - run: echo "TEST_FILTER=FullyQualifiedName!~ConsistencyTests" >> $GITHUB_ENV - - - name: Test - run: dotnet test -c Debug ./src/Microsoft.Unity.Analyzers.Tests --filter ${{env.TEST_FILTER}} - env: - DOTNET_CLI_TELEMETRY_OPTOUT: 1 - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 - DOTNET_NOLOGO: 1 diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml deleted file mode 100644 index 55163d14..00000000 --- a/.github/workflows/ci-macos.yml +++ /dev/null @@ -1,71 +0,0 @@ -name: CI-macOS - -on: - push: - branches: - - main - - release/* - pull_request: - branches: - - main - - release/* - -jobs: - macos: - runs-on: macos-latest - permissions: - actions: read - contents: read - deployments: read - packages: none - pull-requests: write - security-events: write - - steps: - - name: Checkout - uses: actions/checkout@v1 - - - name: Set Environment Variables - uses: ./.github/actions/setvars - with: - varFilePath: ./.github/variables/unity.env - - - name: Setup .NET - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '8.0.x' - include-prerelease: false - - - name: Download Unity - run: curl -o ./unity.pkg -k https://download.unity3d.com/download_unity/${{ env.UNITY_HASH }}/MacEditorInstaller/Unity.pkg - - - name: Install Unity - run: sudo installer -package unity.pkg -target / - - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - - - name: Build - run: dotnet build -c Debug ./src/Microsoft.Unity.Analyzers.sln /p:UseSharedCompilation=false - env: - DOTNET_CLI_TELEMETRY_OPTOUT: 1 - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 - DOTNET_NOLOGO: 1 - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 - - - name: Test context (main) - if: github.ref == 'refs/heads/main' - run: echo "TEST_FILTER=." >> $GITHUB_ENV - - - name: Test context (feature) - if: github.ref != 'refs/heads/main' - run: echo "TEST_FILTER=FullyQualifiedName!~ConsistencyTests" >> $GITHUB_ENV - - - name: Test - run: dotnet test -c Debug ./src/Microsoft.Unity.Analyzers.Tests --filter ${{env.TEST_FILTER}} - env: - DOTNET_CLI_TELEMETRY_OPTOUT: 1 - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 - DOTNET_NOLOGO: 1 diff --git a/.github/workflows/ci-matrix.yml b/.github/workflows/ci-matrix.yml new file mode 100644 index 00000000..6a707f47 --- /dev/null +++ b/.github/workflows/ci-matrix.yml @@ -0,0 +1,99 @@ +name: CI + +on: + push: + branches: + - main + - release/* + pull_request: + branches: + - main + - release/* + +env: + DOTNET_CLI_TELEMETRY_OPTOUT: 1 + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 + DOTNET_NOLOGO: 1 + UNITY_HASH: '887be4894c44' + UNITY_FULL_VERSION: '2022.3.22f1' + +jobs: + compute: + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + deployments: read + packages: none + pull-requests: write + security-events: write + outputs: + UNITY_HASH: ${{ env.UNITY_HASH }} + UNITY_FULL_VERSION: ${{ env.UNITY_FULL_VERSION }} + steps: + - name: Compute outputs + run: | + echo "UNITY_HASH=${{ env.UNITY_HASH }}" >> $GITHUB_OUTPUT + echo "UNITY_FULL_VERSION=${{ env.UNITY_FULL_VERSION }}" >> $GITHUB_OUTPUT + + ci: + strategy: + matrix: + include: + - os: ubuntu + download: curl -o ./Unity.tar.xz -k https://download.unity3d.com/download_unity/${{ needs.compute.outputs.UNITY_HASH }}/LinuxEditorInstaller/Unity.tar.xz + install: mkdir -p ~/Unity && tar -xf Unity.tar.xz -C ~/Unity + - os: macos + download: curl -o ./unity.pkg -k https://download.unity3d.com/download_unity/${{ needs.compute.outputs.UNITY_HASH }}/MacEditorInstaller/Unity.pkg + install: sudo installer -package unity.pkg -target / + - os: windows + download: cmd /c bitsadmin /TRANSFER unity /DOWNLOAD /PRIORITY foreground "https://download.unity3d.com/download_unity/${{ needs.compute.outputs.UNITY_HASH }}/Windows64EditorInstaller/UnitySetup64-${{ needs.compute.outputs.UNITY_FULL_VERSION }}.exe" "%CD%\unitysetup.exe" + install: cmd /c unitysetup.exe /UI=reduced /S /D=%ProgramFiles%\Unity + name: CI-${{ matrix.os }} + runs-on: ${{ matrix.os }}-latest + needs: compute + permissions: + actions: read + contents: read + deployments: read + packages: none + pull-requests: write + security-events: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.0.x' + + - name: Download Unity on ${{ matrix.os }} + run: ${{ matrix.download }} + + - name: Install Unity on ${{ matrix.os }} + run: ${{ matrix.install }} + + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + + - name: Build + run: dotnet build -c Debug ./src/Microsoft.Unity.Analyzers.sln /p:UseSharedCompilation=false + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + + - name: Test context (main) + if: github.ref == 'refs/heads/main' + run: echo "TEST_FILTER=." >> $GITHUB_ENV + shell: bash + + - name: Test context (feature) + if: github.ref != 'refs/heads/main' + run: echo "TEST_FILTER=FullyQualifiedName!~ConsistencyTests" >> $GITHUB_ENV + shell: bash + + - name: Test + run: dotnet test -c Debug ./src/Microsoft.Unity.Analyzers.Tests --filter ${{env.TEST_FILTER}} + shell: bash diff --git a/.github/workflows/ci-windows.yml b/.github/workflows/ci-windows.yml deleted file mode 100644 index ff87f340..00000000 --- a/.github/workflows/ci-windows.yml +++ /dev/null @@ -1,77 +0,0 @@ -name: CI-Windows - -on: - push: - branches: - - main - - release/* - pull_request: - branches: - - main - - release/* - -jobs: - windows: - runs-on: windows-latest - permissions: - actions: read - contents: read - deployments: read - packages: none - pull-requests: write - security-events: write - - steps: - - name: Checkout - uses: actions/checkout@v1 - - - name: Set Environment Variables - uses: ./.github/actions/setvars - with: - varFilePath: ./.github/variables/unity.env - - - name: Setup .NET - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '8.0.x' - include-prerelease: false - - - name: Download Unity - run: bitsadmin /TRANSFER unity /DOWNLOAD /PRIORITY foreground "https://download.unity3d.com/download_unity/${{ env.UNITY_HASH }}/Windows64EditorInstaller/UnitySetup64-${{ env.UNITY_FULL_VERSION }}.exe" "%CD%\unitysetup.exe" - shell: cmd - - - name: Install Unity - run: unitysetup.exe /UI=reduced /S /D=%ProgramFiles%\Unity - shell: cmd - - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - - - name: Build - run: dotnet build -c Debug ./src/Microsoft.Unity.Analyzers.sln /p:UseSharedCompilation=false - env: - DOTNET_CLI_TELEMETRY_OPTOUT: 1 - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 - DOTNET_NOLOGO: 1 - shell: cmd - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 - - - name: Test context (main) - if: github.ref == 'refs/heads/main' - run: echo "TEST_FILTER=." >> $GITHUB_ENV - shell: bash - - - name: Test context (feature) - if: github.ref != 'refs/heads/main' - run: echo "TEST_FILTER=FullyQualifiedName!~ConsistencyTests" >> $GITHUB_ENV - shell: bash - - - name: Test - run: dotnet test -c Debug ./src/Microsoft.Unity.Analyzers.Tests --filter ${{env.TEST_FILTER}} - env: - DOTNET_CLI_TELEMETRY_OPTOUT: 1 - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 - DOTNET_NOLOGO: 1 - shell: cmd diff --git a/README.md b/README.md index 11b79edc..8266f5a3 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # Analyzers for Unity -[![Build status on Windows](https://github.com/microsoft/Microsoft.Unity.Analyzers/workflows/CI-Windows/badge.svg)](https://github.com/microsoft/Microsoft.Unity.Analyzers/actions?query=workflow%3ACI-Windows) -[![Build status on macOS](https://github.com/microsoft/Microsoft.Unity.Analyzers/workflows/CI-macOS/badge.svg)](https://github.com/microsoft/Microsoft.Unity.Analyzers/actions?query=workflow%3ACI-macOS) -[![Build status on Linux](https://github.com/microsoft/Microsoft.Unity.Analyzers/workflows/CI-Linux/badge.svg)](https://github.com/microsoft/Microsoft.Unity.Analyzers/actions?query=workflow%3ACI-Linux) +[![Build status](https://github.com/microsoft/Microsoft.Unity.Analyzers/workflows/CI/badge.svg)](https://github.com/microsoft/Microsoft.Unity.Analyzers/actions?query=workflow%3ACI) [![NuGet](https://img.shields.io/nuget/v/Microsoft.Unity.Analyzers.svg)](https://nuget.org/packages/Microsoft.Unity.Analyzers) This project provides Visual Studio with a better understanding of Unity projects by adding Unity-specific diagnostics or by removing general C# diagnostics that do not apply to Unity projects.