Skip to content

Merge pull request #339 from EricCogen/dependabot/nuget/src/GauntletC… #1399

Merge pull request #339 from EricCogen/dependabot/nuget/src/GauntletC…

Merge pull request #339 from EricCogen/dependabot/nuget/src/GauntletC… #1399

Workflow file for this run

name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build-and-test:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v7
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: 8.0.x
- name: Restore
run: dotnet restore GauntletCI.slnx
- name: Build
run: dotnet build GauntletCI.slnx --no-restore --configuration Release
- name: Test
env:
GAUNTLETCI_E2E_STRICT: "1"
run: dotnet test GauntletCI.slnx --no-build --configuration Release --verbosity normal
update-badge:
name: Update GauntletCI Badge
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: [build-and-test]
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 2
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: 8.0.x
- name: Restore
run: dotnet restore GauntletCI.slnx
- name: Build
run: dotnet build GauntletCI.slnx --no-restore --configuration Release
- name: Pack GauntletCI tool
run: dotnet pack src/GauntletCI.Cli/GauntletCI.Cli.csproj -c Release --no-build -o ./artifacts/nupkg -p:PackageVersion=0.0.0-ci.${{ github.run_number }}
- name: Install GauntletCI from local pack
run: dotnet tool install -g GauntletCI --add-source ./artifacts/nupkg --version 0.0.0-ci.${{ github.run_number }}
- name: Run GauntletCI on last commit
id: analyze
run: |
git diff HEAD~1..HEAD > main.diff
set +e
OUTPUT=$(gauntletci analyze --no-banner --ascii < main.diff 2>&1)
EXIT_CODE=$?
set -e
FINDINGS=$(echo "$OUTPUT" | grep -oP 'Findings\s+:\s+\K\d+' || echo "0")
echo "exit_code=$EXIT_CODE" >> $GITHUB_OUTPUT
echo "findings=$FINDINGS" >> $GITHUB_OUTPUT
- name: Push badge to Gist
env:
GIST_SECRET: ${{ secrets.GIST_SECRET }}
GIST_ID: ${{ vars.GIST_ID }}
run: |
EXIT_CODE="${{ steps.analyze.outputs.exit_code }}"
FINDINGS="${{ steps.analyze.outputs.findings }}"
if [ "$EXIT_CODE" = "0" ]; then
COLOR="brightgreen"
elif [ "$FINDINGS" -gt 10 ]; then
COLOR="red"
else
COLOR="yellow"
fi
PLURAL=$([ "$FINDINGS" = "1" ] && echo "" || echo "s")
MESSAGE="${FINDINGS} finding${PLURAL}"
python3 -c "
import json, sys
badge = {'schemaVersion': 1, 'label': 'GauntletCI', 'message': sys.argv[1], 'color': sys.argv[2]}
payload = {'files': {'gauntletci-badge.json': {'content': json.dumps(badge)}}}
print(json.dumps(payload))
" "$MESSAGE" "$COLOR" | \
curl -s -X PATCH \
-H "Authorization: token $GIST_SECRET" \
-H "Content-Type: application/json" \
-d @- \
"https://api.github.com/gists/$GIST_ID"
gauntletci-analyze:
name: GauntletCI Self-Analysis
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: 8.0.x
- name: Restore
run: dotnet restore GauntletCI.slnx
- name: Build
run: dotnet build GauntletCI.slnx --no-restore --configuration Release
- name: Pack GauntletCI tool
run: dotnet pack src/GauntletCI.Cli/GauntletCI.Cli.csproj -c Release --no-build -o ./artifacts/nupkg -p:PackageVersion=0.0.0-ci.${{ github.run_number }}
- name: Install GauntletCI from local pack
run: dotnet tool install -g GauntletCI --add-source ./artifacts/nupkg --version 0.0.0-ci.${{ github.run_number }}
- name: Generate PR diff
run: git diff ${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }} > pr.diff
- name: Analyze with GauntletCI
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GAUNTLETCI_LICENSE: ${{ secrets.GAUNTLETCI_LICENSE }}
GAUNTLETCI_PR_NUMBER: ${{ github.event.pull_request.number }}
GAUNTLETCI_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
run: |
set -o pipefail
set +e
gauntletci analyze --no-banner --ascii --github-annotations --pr-comment-suggest --repo . \
--severity warn --sensitivity balanced --no-baseline < pr.diff
exit_code=$?
set -e
if [ "$exit_code" -ne 0 ]; then
echo "::error::GauntletCI self-analysis reported block-level findings (exit $exit_code). See annotations and PR comments."
exit "$exit_code"
fi