Refactor AnonymousConstructorDescriptor formatting & docs #7
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: Sync .editorconfig from canonical | |
| on: | |
| push: | |
| pull_request: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| env: | |
| # Replace with your canonical repo and branch if different | |
| CANONICAL_REPO: BionicCode/bioniccode-code-style | |
| CANONICAL_BRANCH: main | |
| jobs: | |
| sync-editorconfig: | |
| # Determine the branch to target: for pull_request use the PR head branch, otherwise use ref_name | |
| env: | |
| TARGET_BRANCH: ${{ github.event.pull_request.head.ref || github.ref_name }} | |
| # true when this run is a pull_request from a fork; used to avoid using secrets for forked PRs | |
| IS_FORK: ${{ github.event.pull_request != null && github.event.pull_request.head.repo.fork == true }} | |
| runs-on: ubuntu-latest | |
| concurrency: | |
| group: sync-editorconfig-${{ github.ref_name }} | |
| cancel-in-progress: true | |
| steps: | |
| - name: Exit if triggered by Actions bot (avoid loops) | |
| if: ${{ github.actor == 'github-actions[bot]' }} | |
| run: | | |
| echo "Triggered by github-actions[bot], exiting to avoid loop." | |
| exit 0 | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Fetch canonical .editorconfig (token clone if available and not a fork, otherwise raw URL) | |
| run: | | |
| set -e | |
| CANONICAL_PATH="BionicCode.CodeStyle/BionicCode.CodeStyle/.editorconfig" | |
| RAW_URL="https://raw.githubusercontent.com/${{ env.CANONICAL_REPO }}/${{ env.CANONICAL_BRANCH }}/${CANONICAL_PATH}" | |
| echo "Canonical repo: ${{ env.CANONICAL_REPO }} (branch: ${{ env.CANONICAL_BRANCH }})" | |
| echo "Using raw URL: $RAW_URL" | |
| # Only attempt token clone if a token is present AND this is not a forked PR | |
| if [ -n "${{ secrets.CANONICAL_REPO_TOKEN }}" ] && [ "${{ env.IS_FORK }}" != "true" ]; then | |
| echo "Attempting authenticated clone of canonical repository" | |
| git clone --depth 1 https://x-access-token:${{ secrets.CANONICAL_REPO_TOKEN }}@github.com/${{ env.CANONICAL_REPO }} canonical-repo || true | |
| if [ -f canonical-repo/.editorconfig ]; then | |
| cp canonical-repo/.editorconfig canonical.editorconfig | |
| echo "Fetched canonical .editorconfig via authenticated clone." | |
| else | |
| echo "Authenticated clone succeeded but canonical .editorconfig not found in canonical-repo" | |
| fi | |
| else | |
| echo "No usable token (or forked PR). Falling back to public raw URL" | |
| curl -fsSL "$RAW_URL" -o canonical.editorconfig || true | |
| if [ -s canonical.editorconfig ]; then | |
| echo "Fetched canonical .editorconfig via public raw URL." | |
| else | |
| echo "Failed to fetch canonical.editorconfig from raw URL" | |
| fi | |
| fi | |
| - name: Ensure we have a canonical file | |
| run: | | |
| if [ ! -s canonical.editorconfig ]; then | |
| echo "Error: canonical.editorconfig not available. Aborting." >&2 | |
| exit 1 | |
| fi | |
| - name: Compare with repository .editorconfig | |
| id: compare | |
| run: | | |
| if [ -f .editorconfig ] && cmp -s .editorconfig canonical.editorconfig; then | |
| echo "same=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "same=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Prepare workspace with canonical .editorconfig | |
| if: steps.compare.outputs.same == 'false' | |
| run: | | |
| # Overwrite or create the repo's .editorconfig with the canonical file | |
| cp canonical.editorconfig .editorconfig | |
| # Show diff for logs (first 200 lines) | |
| echo "---- .editorconfig (canonical) ----" | |
| sed -n '1,200p' canonical.editorconfig || true | |
| echo "-----------------------------------" | |
| - name: Create sync pull request if .editorconfig differs or missing | |
| if: steps.compare.outputs.same == 'false' | |
| uses: peter-evans/create-pull-request@v5 | |
| with: | |
| # new branch name for sync commit | |
| branch: sync-editorconfig/${{ github.run_id }} | |
| # target the branch that triggered the run (developer's branch) | |
| base: ${{ env.TARGET_BRANCH }} | |
| title: "chore: sync .editorconfig with canonical" | |
| body: | | |
| This automated PR updates or adds .editorconfig from the canonical repository (${{ env.CANONICAL_REPO }}@${{ env.CANONICAL_BRANCH }}). | |
| Please merge or pull this update to ensure your local analyzers and formatting use the canonical rules. | |
| commit-message: "chore(sync): update .editorconfig from canonical" | |
| labels: automation | |
| # The action will pick up changes in the working directory; specifying file-pattern helps | |
| file-pattern: .editorconfig | |
| # Author set to the GitHub Actions bot to make automated commits identifiable | |
| author: "github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>" |