Added generator actions to keep the generated files fresh. #6
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: PR Type Generation | |
| on: | |
| pull_request: | |
| paths: | |
| - 'Generator/*.*' | |
| - 'Types/**/*.g.cs' | |
| - '.github/workflows/pr-generator.yml' | |
| jobs: | |
| generate-and-commit: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write # Needed to allow push with GITHUB_TOKEN | |
| steps: | |
| - name: Checkout PR branch | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ github.head_ref }} | |
| - name: Check last commit author | |
| id: last-commit | |
| run: | | |
| AUTHOR=$(git log -1 --pretty=format:'%an') | |
| echo "author=$AUTHOR" >> $GITHUB_OUTPUT | |
| - name: Setup .NET 9 | |
| if: steps.last-commit.outputs.author != 'github-actions[bot]' | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: '9.0.x' | |
| - name: Restore dependencies | |
| if: steps.last-commit.outputs.author != 'github-actions[bot]' | |
| run: dotnet restore | |
| - name: Run generator | |
| if: steps.last-commit.outputs.author != 'github-actions[bot]' | |
| run: dotnet run --project Generator/System.Management.Generator.csproj | |
| - name: Check for changes | |
| if: steps.last-commit.outputs.author != 'github-actions[bot]' | |
| id: git-check | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| git add Types/**/*.g.cs || true | |
| if git diff --cached --quiet; then | |
| echo "no_changes=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "no_changes=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Set up authentication for push | |
| if: steps.last-commit.outputs.author != 'github-actions[bot]' && steps.git-check.outputs.no_changes == 'false' | |
| run: | | |
| git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Commit and push changes to PR branch | |
| if: steps.last-commit.outputs.author != 'github-actions[bot]' && steps.git-check.outputs.no_changes == 'false' | |
| run: | | |
| git commit -m "chore(types): update generated types (PR auto-update)" | |
| git push | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |