|
1 | 1 | name: Format |
2 | 2 |
|
3 | | -on: |
| 3 | +on: |
4 | 4 | push: |
5 | | - workflow_run: |
6 | | - workflows: |
7 | | - - Create Prerelease |
8 | | - - Create Release |
9 | | - types: [requested] |
10 | 5 | workflow_dispatch: |
11 | 6 | pull_request: |
12 | | - types: [opened,edited,synchronize,reopened] |
13 | | - branches: |
14 | | - - main |
15 | | - - develop |
| 7 | + types: [opened, edited, synchronize, reopened] |
| 8 | + branches: [main, develop] |
| 9 | + |
| 10 | + workflow_run: |
| 11 | + workflows: [Create Prerelease, Create Release] |
| 12 | + types: [requested] |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: write |
| 16 | + pull-requests: write |
| 17 | + actions: read |
16 | 18 |
|
17 | | -env: |
18 | | - DOTNET_VERSION: '9.0.x' |
19 | | - |
20 | 19 | jobs: |
21 | | - format: |
| 20 | + discover: |
22 | 21 | runs-on: ubuntu-latest |
| 22 | + outputs: |
| 23 | + branch_name: ${{ steps.set_branch.outputs.branch_name }} |
23 | 24 |
|
24 | 25 | steps: |
25 | | - - name: Checkout Code |
26 | | - uses: actions/checkout@v4 |
27 | | - |
28 | | - - name: Setup .NET |
29 | | - uses: actions/setup-dotnet@v4 |
30 | | - with: |
31 | | - dotnet-version: ${{ env.DOTNET_VERSION }} |
32 | | - |
33 | | - - name: Format |
34 | | - run: dotnet format |
| 26 | + - id: set_branch |
| 27 | + shell: bash |
| 28 | + run: | |
| 29 | + # 1. Pick the raw branch/ref for each trigger type |
| 30 | + if [[ "${{ github.event_name }}" == "workflow_run" ]]; then |
| 31 | + RAW='${{ github.event.workflow_run.head_branch }}' |
| 32 | + elif [[ "${{ github.event_name }}" == "pull_request" ]]; then |
| 33 | + RAW='${{ github.event.pull_request.base.ref }}' |
| 34 | + else |
| 35 | + RAW='${{ github.ref }}' |
| 36 | + fi |
35 | 37 |
|
36 | | - - name: Update Styles |
37 | | - continue-on-error: true |
38 | | - run: | |
39 | | - git config --global user.name 'github-actions' |
40 | | - git config --global user.email '[email protected]' |
41 | | - git commit -am "Updated code formatting to match rules in .editorconfig" |
42 | | - git push |
| 38 | + # 2. Strip the refs/heads/ prefix if present |
| 39 | + CLEAN="${RAW#refs/heads/}" |
43 | 40 |
|
| 41 | + echo "Detected branch: $CLEAN" |
| 42 | + echo "branch_name=$CLEAN" >> "$GITHUB_OUTPUT" |
| 43 | + |
| 44 | + format: |
| 45 | + needs: discover |
| 46 | + if: ${{ needs.discover.result == 'success' }} |
| 47 | + uses: Stillpoint-Software/shared-workflows/.github/workflows/format.yml@main |
| 48 | + with: |
| 49 | + dotnet_version: "9.0.x" |
| 50 | + branch: ${{ needs.discover.outputs.branch_name }} |
| 51 | + secrets: inherit |
| 52 | + |
0 commit comments