Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub workflows #2

Merged
merged 6 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: 2

updates:
- package-ecosystem: "nuget"
directory: "/"
schedule:
interval: weekly
open-pull-requests-limit: 50
assignees:
- "guibranco"
reviewers:
- "guibranco"
labels:
- "nuget"
- ".NET"
- "packages"
- "dependencies"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: weekly
open-pull-requests-limit: 50
assignees:
- "guibranco"
reviewers:
- "guibranco"
labels:
- "github-actions"
- "dependencies"
Comment on lines +1 to +30
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CODE REVIEW

  1. Open Pull Requests Limit: 50 might be excessive and could overwhelm. Consider reducing the limit.

  2. Assignees and Reviewers: Ensure redundancy; having only one person might delay responses.

  3. YAML Formatting: Consistent indentation enhances readability.

Example improvements:

version: 2

updates:
- package-ecosystem: "nuget"
  directory: "/"
  schedule:
    interval: weekly
  open-pull-requests-limit: 10
  assignees: 
    - "guibranco"
    - "alternateReviewer"
  reviewers: 
    - "guibranco"
    - "alternateReviewer"
  labels:
    - "nuget"
    - ".NET"
    - "packages"
    - "dependencies"

- package-ecosystem: "github-actions"
  directory: "/"
  schedule:
    interval: weekly
  open-pull-requests-limit: 10
  assignees: 
    - "guibranco"
    - "alternateReviewer"
  reviewers: 
    - "guibranco"
    - "alternateReviewer"
  labels:
    - "github-actions"
    - "dependencies"

36 changes: 36 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build

on:
push:
branches:
- '*'
- '*/*'
- '**'
- '!main'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: Build
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '7.0.x'

- name: Build solution
run: dotnet build -c Debug

- name: Run tests
run: dotnet test -c Debug --no-build --no-restore
Comment on lines +1 to +36
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CODE REVIEW

  1. Branch Patterns: Simplify branch patterns to avoid redundancy.
  2. Version Lock: Specify exact versions for greater control over dependencies.
  3. Job Naming: Use more descriptive job names.

Revised code example:

name: Build

on:
  push:
    branches:
      - '**'
      - '!main'
  workflow_dispatch:

concurrency: 
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build:
    name: Build and Test on Ubuntu
    runs-on: ubuntu-latest    

    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Setup .NET
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: '7.0.400'

      - name: Build solution
        run: dotnet build -c Debug

      - name: Run tests
        run: dotnet test -c Debug --no-build --no-restore

33 changes: 33 additions & 0 deletions .github/workflows/deep-source.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Deep Source

on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]

jobs:
DeepSource:
name: Deep Source Coverage report
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Install DeepSource scanner
run: curl https://deepsource.io/cli | sh

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '7.0.x'

- name: Build and analyze
env:
DEEPSOURCE_DSN: ${{ secrets.DEEPSOURCE_DSN }}
run: |
dotnet build -c Debug --verbosity minimal
dotnet test -c Debug --verbosity minimal --no-build --no-restore /p:CollectCoverage=true /p:CoverletOutputFormat="cobertura"
./bin/deepsource report --analyzer test-coverage --key csharp --value-file ./Tests/POCYamlHandling.Tests/coverage.cobertura.xml
Comment on lines +1 to +33
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CODE REVIEW

Overall, this workflow looks solid. Here are some minor improvements for better readability and consistency:

  1. Define the DeepSource scanner installation as a versioned action.
  2. Use dotnet instead of deprecated custom scripts for coverage.
name: Deep Source

on:
  push:
    branches:
      - main
  pull_request:
    types: [opened, synchronize, reopened]

jobs:
  DeepSource:
    name: Deep Source Coverage report
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.head.sha }}

      - name: Install DeepSource scanner
        run: curl https://deepsource.io/cli | sh -s -- --version 1.6.0

      - name: Setup .NET
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: '7.0.x'

      - name: Build and analyze
        env:
          DEEPSOURCE_DSN: ${{ secrets.DEEPSOURCE_DSN }}
        run: |
          dotnet build -c Debug --verbosity minimal
          dotnet test -c Debug --verbosity minimal --no-build --no-restore /p:CollectCoverage=true /p:CoverletOutputFormat="cobertura"
          deepsource report --analyzer test-coverage --key csharp --value-file ./Tests/POCYamlHandling.Tests/coverage.cobertura.xml

This enhances readability and maintains version consistency for the DeepSource scanner.

75 changes: 75 additions & 0 deletions .github/workflows/infisical-secrets-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Infisical secrets check

on:
workflow_dispatch:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:

secrets-scan:
runs-on: ubuntu-latest
steps:

- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set Infisical package source
shell: bash
run: curl -1sLf 'https://dl.cloudsmith.io/public/infisical/infisical-cli/setup.deb.sh' | sudo -E bash

- name: Install Infisical
shell: bash
run: |
sudo apt-get update && sudo apt-get install -y infisical

- name: Run scan
shell: bash
run: infisical scan --redact -f csv -r secrets-result.csv 2>&1 | tee >(sed -r 's/\x1b\[[0-9;]*m//g' > secrets-result.log)

- name: Read secrets-result.log
uses: guibranco/github-file-reader-action-v2@v2.2.583
if: always()
id: log
with:
path: secrets-result.log

- name: Read secrets-result.log
uses: guibranco/github-file-reader-action-v2@v2.2.583
if: failure()
id: report
with:
path: secrets-result.csv

- name: Update PR with comment
uses: mshick/add-pr-comment@v2
if: always()
with:
refresh-message-position: true
message-id: 'secrets-result'
message: |
**Infisical secrets check:** :white_check_mark: No secrets leaked!

**Scan results:**
```
${{ steps.log.outputs.contents }}
```

message-failure: |
**Infisical secrets check:** :rotating_light: Secrets leaked!

**Scan results:**
```
${{ steps.log.outputs.contents }}
```
**Scan report:**
```
${{ steps.report.outputs.contents }}
```
message-cancelled: |
**Infisical secrets check:** :o: Secrets check cancelled!
Comment on lines +1 to +75
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CODE REVIEW

Feedback:

  1. Consolidate duplicated steps to reduce redundancy.
  2. Use a consistent indentation for better readability.

Improvements:

  1. Combine duplicate Read secrets-result.log steps.
  2. Enhance message distinction using GitHub Actions condition variables.
- name: Read secrets-result.log
  uses: guibranco/github-file-reader-action-v2@v2.2.583
  if: always()
  id: log
  with:
    path: secrets-result.log

- name: Read secrets-result.csv
  uses: guibranco/github-file-reader-action-v2@v2.2.583
  if: failure()
  id: report
  with:
    path: secrets-result.csv

24 changes: 24 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Linter check

on:
workflow_dispatch:
pull_request:

jobs:
linter-check:
runs-on: ubuntu-latest
steps:

- name: Checkout repo
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4

- name: Dotnet restore
run: dotnet tool restore

- name: CSharpier format check
run: |
dotnet csharpier . --check
echo "run 'dotnet build' to fix the formatting of the code automatically"
Comment on lines +1 to +24
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CODE REVIEW

  1. Consistency in action versions: While actions/checkout uses version v4, setup-dotnet should use the same versioning format. Prefer @v2 wherever possible.

  2. Fail-fast approach: The echo message should be displayed only when formatting check fails.

  3. Naming consistency: Use consistent naming conventions for steps.

name: Linter check

on:
  workflow_dispatch:
  pull_request:

jobs:
  linter-check:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        
      - name: Setup .NET environment
        uses: actions/setup-dotnet@v2
        
      - name: Restore .NET tools
        run: dotnet tool restore
        
      - name: Check CSharpier formatting
        run: |
          dotnet csharpier . --check || echo "Run 'dotnet build' to automatically fix the formatting of the code."

17 changes: 17 additions & 0 deletions .github/workflows/size-label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Label based on PR size

on:
workflow_dispatch:
pull_request:

jobs:
size-label:
permissions: write-all
runs-on: ubuntu-latest

steps:

- name: size-label
uses: "pascalgn/size-label-action@v0.5.2"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
Comment on lines +1 to +17
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CODE REVIEW

  1. Use YAML indentation best practices.
  2. Add a job name for better readability.
  3. Remove unnecessary quotes around the uses directive.
name: Label based on PR size

on:
  workflow_dispatch:
  pull_request:

jobs:
  size-label:
    permissions: write-all
    runs-on: ubuntu-latest

    steps:
      - name: Apply size label
        uses: pascalgn/size-label-action@v0.5.2
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Loading