diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index addc01cdb..ba1a60acb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,6 +29,73 @@ env: TEST_RESULTS: "results/" jobs: + calc-version: + runs-on: ubuntu-latest + + outputs: + semVer: ${{ steps.gitversion.outputs.semVer }} + preReleaseLabel: ${{ steps.gitversion.outputs.preReleaseLabel }} + majorMinorPatch: ${{ steps.gitversion.outputs.majorMinorPatch }} + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Install GitVersion + run: dotnet tool install --global GitVersion.Tool + + - name: Determine Version + id: gitversion + uses: gittools/actions/gitversion/execute@v0.9.11 + with: + useConfigFile: true + configFilePath: .github/.gitversion.yml + + analyze: + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + strategy: + fail-fast: false + matrix: + language: [ 'csharp' ] + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: actions/setup-dotnet@v1 + with: + dotnet-version: "6.0.x" + + - name: Enable NuGet cache + uses: actions/cache@v2.1.7 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} + restore-keys: | + ${{ runner.os }}-nuget + + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + + - name: Restore dependencies + run: dotnet restore + working-directory: ./src + + - name: Build Solution + run: dotnet build -c ${{ env.BUILD_CONFIG }} --nologo ${{ env.SOLUTION }} + working-directory: ./src + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 + unit-test: runs-on: ${{ matrix.os }} strategy: @@ -45,12 +112,20 @@ jobs: - uses: actions/setup-dotnet@v1 with: dotnet-version: "6.0.x" + + - name: Enable NuGet cache + uses: actions/cache@v2.1.7 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} + restore-keys: | + ${{ runner.os }}-nuget - name: Restore dependencies run: dotnet restore working-directory: ./src - - name: Build All + - name: Build Solution run: dotnet build -c ${{ env.BUILD_CONFIG }} --nologo ${{ env.SOLUTION }} working-directory: ./src @@ -70,6 +145,7 @@ jobs: build: runs-on: ${{ matrix.os }} + needs: [calc-version] strategy: matrix: os: [ubuntu-latest, windows-latest] @@ -81,11 +157,6 @@ jobs: checks: write security-events: write - outputs: - semVer: ${{ steps.gitversion.outputs.semVer }} - preReleaseLabel: ${{ steps.gitversion.outputs.preReleaseLabel }} - majorMinorPatch: ${{ steps.gitversion.outputs.majorMinorPatch }} - steps: - name: Checkout repository uses: actions/checkout@v2 @@ -96,21 +167,19 @@ jobs: with: dotnet-version: "6.0.x" - - name: Install GitVersion - run: dotnet tool install --global GitVersion.Tool - - - name: Determine Version - id: gitversion - uses: gittools/actions/gitversion/execute@v0.9.11 + - name: Enable NuGet cache + uses: actions/cache@v2.1.7 with: - useConfigFile: true - configFilePath: .github/.gitversion.yml + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} + restore-keys: | + ${{ runner.os }}-nuget - name: Restore dependencies run: dotnet restore working-directory: ./src - - name: Build All + - name: Build Solution run: dotnet build -c ${{ env.BUILD_CONFIG }} --nologo ${{ env.SOLUTION }} working-directory: ./src @@ -134,7 +203,7 @@ jobs: popd dir -r ~/release - - name: Upload Artifact + - name: Upload CLI uses: actions/upload-artifact@v2.3.1 with: name: cli @@ -143,7 +212,7 @@ jobs: - name: Log in to the Container registry uses: docker/login-action@v1.12.0 - if: ${{ (github.event_name != 'pull_request') && (matrix.os == 'ubuntu-latest') }} + if: ${{ (matrix.os == 'ubuntu-latest') }} with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} @@ -152,7 +221,7 @@ jobs: - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@v3.6.2 - if: ${{ (github.event_name != 'pull_request') && (matrix.os == 'ubuntu-latest') }} + if: ${{ (matrix.os == 'ubuntu-latest') }} with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | @@ -161,10 +230,10 @@ jobs: - name: Build and push Docker image uses: docker/build-push-action@v2.9.0 - if: ${{ (github.event_name != 'pull_request') && (matrix.os == 'ubuntu-latest') }} + if: ${{ (matrix.os == 'ubuntu-latest') }} with: context: . - push: true + push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} @@ -172,14 +241,14 @@ jobs: env: TRIVY_TIMEOUT_SEC: 360s uses: Azure/container-scan@v0.1 - if: ${{ (github.event_name != 'pull_request') && (matrix.os == 'ubuntu-latest') }} + if: ${{ (matrix.os == 'ubuntu-latest') }} with: image-name: ${{ fromJSON(steps.meta.outputs.json).tags[0] }} - name: Anchore container scan id: anchore-scan uses: anchore/scan-action@v3.2.0 - if: ${{ (github.event_name != 'pull_request') && (matrix.os == 'ubuntu-latest') }} + if: ${{ (matrix.os == 'ubuntu-latest') }} with: image: ${{ fromJSON(steps.meta.outputs.json).tags[0] }} fail-build: true @@ -187,22 +256,41 @@ jobs: - name: Upload Anchore scan SARIF report uses: github/codeql-action/upload-sarif@v1 - if: ${{ (github.event_name != 'pull_request') && (matrix.os == 'ubuntu-latest') }} + if: ${{ (matrix.os == 'ubuntu-latest') }} with: sarif_file: ${{ steps.anchore-scan.outputs.sarif }} token: ${{ secrets.GITHUB_TOKEN }} docs: runs-on: ubuntu-latest + needs: [calc-version] + env: + SEMVER: ${{ needs.calc-version.outputs.semVer }} steps: - uses: actions/checkout@v2 with: fetch-depth: 0 + + - uses: actions/setup-dotnet@v1 + with: + dotnet-version: "6.0.x" + + - name: Enable NuGet cache + uses: actions/cache@v2.1.7 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} + restore-keys: | + ${{ runner.os }}-nuget + + - name: Restore dependencies + run: dotnet restore + working-directory: ./src - name: Update docs version run: | - sed -i -e "s,v0.0.0,v$GitVersion_SemVer,g" ./docs/docfx.json - sed -i -e "s,v0.0.0,v$GitVersion_SemVer,g" ./docs/index.md + sed -i -e "s,v0.0.0,v$SEMVER,g" ./docs/docfx.json + sed -i -e "s,v0.0.0,v$SEMVER,g" ./docs/index.md - uses: nikeee/docfx-action@v1.0.0 name: Build Docs @@ -213,7 +301,7 @@ jobs: run: | mkdir ~/release pushd docs/_site - zip -r ~/release/mig-docs-${GitVersion_SemVer}.zip * + zip -r ~/release/mig-docs-${SEMVER}.zip * popd ls -lR ~/release @@ -229,9 +317,9 @@ jobs: runs-on: ubuntu-latest needs: [build, unit-test, docs] env: - SEMVER: ${{ needs.build.outputs.semVer }} - PRERELEASELABEL: ${{ needs.build.outputs.preReleaseLabel }} - MAJORMINORPATCH: ${{ needs.build.outputs.majorMinorPatch }} + SEMVER: ${{ needs.calc-version.outputs.semVer }} + PRERELEASELABEL: ${{ needs.calc-version.outputs.preReleaseLabel }} + MAJORMINORPATCH: ${{ needs.calc-version.outputs.majorMinorPatch }} steps: - uses: actions/checkout@v2 @@ -266,9 +354,9 @@ jobs: milestone: ${{ env.MAJORMINORPATCH }} name: "Release ${{ env.MAJORMINORPATCH }}" assets: | - release/mig-cli-linux-x64.zip - release/mig-cli-windows-x64.zip - release/mig-docs-${SEMVER}.zip + release/cli/mig-cli-linux-x64.zip + release/cli/mig-cli-windows-x64.zip + release/docs/mig-docs-${SEMVER}.zip - name: Publish release with GitReleaseManager uses: gittools/actions/gitreleasemanager/publish@v0.9.11 diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index fa06ad0bf..000000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,70 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "CodeQL" - -on: - push: - branches: [ main ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ main ] - schedule: - - cron: '35 21 * * 4' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ 'csharp' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] - # Learn more about CodeQL language support at https://git.io/codeql-language-support - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v1 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v1 - - # â„šī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # âœī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1