From f20e40ee13942339c392ea1ead2de3c471f30df3 Mon Sep 17 00:00:00 2001 From: Alexander Alemayhu Date: Sun, 20 Jul 2025 17:24:11 +0200 Subject: [PATCH 01/11] chore: add prettier actions --- .github/workflows/format.yaml | 75 +++++++++++++++++++++++++++++++++++ .prettierignore | 22 ++++++++++ .prettierrc | 10 +++++ 3 files changed, 107 insertions(+) create mode 100644 .github/workflows/format.yaml create mode 100644 .prettierignore create mode 100644 .prettierrc diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml new file mode 100644 index 0000000..07a683a --- /dev/null +++ b/.github/workflows/format.yaml @@ -0,0 +1,75 @@ +# File: .github/workflows/format.yml +name: Format Code with Prettier + +on: + pull_request: + branches: + - main + push: + branches: + - main + +jobs: + prettier: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + issues: write + + steps: + # 1. Check out the repo with token that can push + - name: Checkout repository + uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + fetch-depth: 0 + + # 2. Set up Node.js + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + # 3. Install Prettier globally + - name: Install Prettier + run: npm install -g prettier + + # 4. Check if Prettier would make changes + - name: Check Prettier formatting + id: prettier-check + run: | + if prettier --check .; then + echo "needs_formatting=false" >> $GITHUB_OUTPUT + echo "✅ Code is already formatted" + exit 0 + else + echo "needs_formatting=true" >> $GITHUB_OUTPUT + echo "❌ Code needs formatting" + exit 1 + fi + continue-on-error: true + + # 5. Run Prettier if needed + - name: Run Prettier + if: steps.prettier-check.outputs.needs_formatting == 'true' + run: prettier --write . + + # 6. Commit & push any changes (only on push to main, not PRs) + - name: Commit formatted code + if: steps.prettier-check.outputs.needs_formatting == 'true' && github.event_name == 'push' + run: | + # Configure git user + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + # Stage changes + git add . + + # Only commit if there are changes + if [ -n "$(git diff --cached)" ]; then + git commit -m "chore: format code with Prettier [skip ci]" + git push + else + echo "🎉 No formatting changes to commit." + fi diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..68b93f5 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,22 @@ +# Ignore build outputs +target/ +node_modules/ + +# Ignore generated files +*.min.js +*.min.css + +# Ignore specific data files that have special formatting +conferences.json +communities.json +conferences.js + +# Ignore vendor files +vendor/ + +# Ignore git files +.git/ + +# Ignore lock files +package-lock.json +yarn.lock diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..346219b --- /dev/null +++ b/.prettierrc @@ -0,0 +1,10 @@ +{ + "semi": true, + "trailingComma": "es5", + "singleQuote": true, + "printWidth": 100, + "tabWidth": 2, + "useTabs": false, + "bracketSpacing": true, + "arrowParens": "avoid" +} \ No newline at end of file From 896c0448b802dec94063aa9d79da2c435116ab4a Mon Sep 17 00:00:00 2001 From: Markus Tacker Date: Sun, 20 Jul 2025 21:19:45 +0200 Subject: [PATCH 02/11] Update .github/workflows/format.yaml --- .github/workflows/format.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml index 07a683a..2699962 100644 --- a/.github/workflows/format.yaml +++ b/.github/workflows/format.yaml @@ -29,7 +29,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '18' + node-version: '22' # 3. Install Prettier globally - name: Install Prettier From 600c6e5e87acbae03c000b9448f2011a5ef939bf Mon Sep 17 00:00:00 2001 From: Markus Tacker Date: Sun, 20 Jul 2025 21:21:44 +0200 Subject: [PATCH 03/11] Update .github/workflows/format.yaml --- .github/workflows/format.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml index 2699962..19ff2ba 100644 --- a/.github/workflows/format.yaml +++ b/.github/workflows/format.yaml @@ -57,7 +57,7 @@ jobs: # 6. Commit & push any changes (only on push to main, not PRs) - name: Commit formatted code - if: steps.prettier-check.outputs.needs_formatting == 'true' && github.event_name == 'push' + if: steps.prettier-check.outputs.needs_formatting == 'true' run: | # Configure git user git config user.name "github-actions[bot]" From 9cfe190cad42cbc04c4206709a1fb116cf3f6d90 Mon Sep 17 00:00:00 2001 From: Markus Tacker Date: Sun, 20 Jul 2025 21:26:21 +0200 Subject: [PATCH 04/11] fix: cleanup --- .github/workflows/format.yaml | 10 ---------- .prettierignore | 23 +---------------------- 2 files changed, 1 insertion(+), 32 deletions(-) diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml index 19ff2ba..25e5ee2 100644 --- a/.github/workflows/format.yaml +++ b/.github/workflows/format.yaml @@ -1,4 +1,3 @@ -# File: .github/workflows/format.yml name: Format Code with Prettier on: @@ -18,24 +17,17 @@ jobs: issues: write steps: - # 1. Check out the repo with token that can push - name: Checkout repository uses: actions/checkout@v4 with: token: ${{ secrets.GITHUB_TOKEN }} fetch-depth: 0 - # 2. Set up Node.js - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '22' - # 3. Install Prettier globally - - name: Install Prettier - run: npm install -g prettier - - # 4. Check if Prettier would make changes - name: Check Prettier formatting id: prettier-check run: | @@ -50,12 +42,10 @@ jobs: fi continue-on-error: true - # 5. Run Prettier if needed - name: Run Prettier if: steps.prettier-check.outputs.needs_formatting == 'true' run: prettier --write . - # 6. Commit & push any changes (only on push to main, not PRs) - name: Commit formatted code if: steps.prettier-check.outputs.needs_formatting == 'true' run: | diff --git a/.prettierignore b/.prettierignore index 68b93f5..9f97022 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,22 +1 @@ -# Ignore build outputs -target/ -node_modules/ - -# Ignore generated files -*.min.js -*.min.css - -# Ignore specific data files that have special formatting -conferences.json -communities.json -conferences.js - -# Ignore vendor files -vendor/ - -# Ignore git files -.git/ - -# Ignore lock files -package-lock.json -yarn.lock +target/ \ No newline at end of file From ad203685e535179483214ccf0eaab1f7e05a352e Mon Sep 17 00:00:00 2001 From: Markus Tacker Date: Sun, 20 Jul 2025 21:39:34 +0200 Subject: [PATCH 05/11] fix: use npx (which installs) --- .github/workflows/format.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml index 25e5ee2..e3c3d06 100644 --- a/.github/workflows/format.yaml +++ b/.github/workflows/format.yaml @@ -15,7 +15,7 @@ jobs: contents: write pull-requests: write issues: write - + steps: - name: Checkout repository uses: actions/checkout@v4 @@ -44,7 +44,7 @@ jobs: - name: Run Prettier if: steps.prettier-check.outputs.needs_formatting == 'true' - run: prettier --write . + run: npx prettier --write . - name: Commit formatted code if: steps.prettier-check.outputs.needs_formatting == 'true' From 8ad4da43d27989147e3ef833d3a063ce5ccc3c27 Mon Sep 17 00:00:00 2001 From: Markus Tacker Date: Sun, 20 Jul 2025 21:41:42 +0200 Subject: [PATCH 06/11] fix: push to current branch --- .github/workflows/format.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml index e3c3d06..4e74777 100644 --- a/.github/workflows/format.yaml +++ b/.github/workflows/format.yaml @@ -59,7 +59,7 @@ jobs: # Only commit if there are changes if [ -n "$(git diff --cached)" ]; then git commit -m "chore: format code with Prettier [skip ci]" - git push + git push origin HEAD:${{ github.head_ref }} else echo "🎉 No formatting changes to commit." fi From 6b50ee8b16d85f910e3f8669efd76ecce7d2b65f Mon Sep 17 00:00:00 2001 From: Markus Tacker Date: Sun, 20 Jul 2025 21:50:23 +0200 Subject: [PATCH 07/11] fix: checkout fork if PR --- .babelrc | 10 +++------- .github/workflows/format.yaml | 6 ++++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/.babelrc b/.babelrc index 0a9ba4b..25f934a 100644 --- a/.babelrc +++ b/.babelrc @@ -13,12 +13,8 @@ "env": { "test": { - "presets": [ - [ - "@babel/preset-env" - ] - ], + "presets": [["@babel/preset-env"]], "plugins": [] - }, - }, + } + } } diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml index 4e74777..893115d 100644 --- a/.github/workflows/format.yaml +++ b/.github/workflows/format.yaml @@ -21,6 +21,8 @@ jobs: uses: actions/checkout@v4 with: token: ${{ secrets.GITHUB_TOKEN }} + repository: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name || github.repository }} + ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref }} fetch-depth: 0 - name: Setup Node.js @@ -46,7 +48,7 @@ jobs: if: steps.prettier-check.outputs.needs_formatting == 'true' run: npx prettier --write . - - name: Commit formatted code + - name: Commit and push formatted code if: steps.prettier-check.outputs.needs_formatting == 'true' run: | # Configure git user @@ -59,7 +61,7 @@ jobs: # Only commit if there are changes if [ -n "$(git diff --cached)" ]; then git commit -m "chore: format code with Prettier [skip ci]" - git push origin HEAD:${{ github.head_ref }} + git push else echo "🎉 No formatting changes to commit." fi From 703cf63695ff944c6572194b6d93805dee3f88b4 Mon Sep 17 00:00:00 2001 From: Markus Tacker Date: Sun, 20 Jul 2025 21:54:29 +0200 Subject: [PATCH 08/11] fix: just format main --- .github/workflows/format.yaml | 12 +----------- .github/workflows/tests.yaml | 4 ++-- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml index 893115d..677fc80 100644 --- a/.github/workflows/format.yaml +++ b/.github/workflows/format.yaml @@ -4,25 +4,15 @@ on: pull_request: branches: - main - push: - branches: - - main jobs: prettier: runs-on: ubuntu-latest - permissions: - contents: write - pull-requests: write - issues: write steps: - name: Checkout repository uses: actions/checkout@v4 with: - token: ${{ secrets.GITHUB_TOKEN }} - repository: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name || github.repository }} - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref }} fetch-depth: 0 - name: Setup Node.js @@ -33,7 +23,7 @@ jobs: - name: Check Prettier formatting id: prettier-check run: | - if prettier --check .; then + if npx prettier --check .; then echo "needs_formatting=false" >> $GITHUB_OUTPUT echo "✅ Code is already formatted" exit 0 diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 08b4b6b..c48d325 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -12,8 +12,8 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v3 with: - node-version-file: '.nvmrc' - cache: 'npm' + node-version-file: '.nvmrc' + cache: 'npm' - name: Install dependencies run: npm ci --no-audit - name: Test From 3eee9f12a9b998c9333dadc5322f4c5cb29ae2f1 Mon Sep 17 00:00:00 2001 From: Markus Tacker Date: Sun, 20 Jul 2025 21:56:22 +0200 Subject: [PATCH 09/11] ci: can we write? --- .github/workflows/format.yaml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml index 677fc80..ce1eba4 100644 --- a/.github/workflows/format.yaml +++ b/.github/workflows/format.yaml @@ -4,6 +4,12 @@ on: pull_request: branches: - main + push: + branches: + - main + +permissions: + contents: write jobs: prettier: @@ -13,6 +19,9 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 with: + token: ${{ secrets.GITHUB_TOKEN }} + repository: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name || github.repository }} + ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref }} fetch-depth: 0 - name: Setup Node.js @@ -23,7 +32,7 @@ jobs: - name: Check Prettier formatting id: prettier-check run: | - if npx prettier --check .; then + if prettier --check .; then echo "needs_formatting=false" >> $GITHUB_OUTPUT echo "✅ Code is already formatted" exit 0 From 762ba0b5e4564dbe394f3230665109c5b0ba4720 Mon Sep 17 00:00:00 2001 From: Markus Tacker Date: Sun, 20 Jul 2025 22:03:01 +0200 Subject: [PATCH 10/11] fix: comment if needed --- .github/workflows/format.yaml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml index ce1eba4..3da17af 100644 --- a/.github/workflows/format.yaml +++ b/.github/workflows/format.yaml @@ -47,8 +47,20 @@ jobs: if: steps.prettier-check.outputs.needs_formatting == 'true' run: npx prettier --write . + - name: Comment on PR about formatting + if: steps.prettier-check.outputs.needs_formatting == 'true' && github.event_name == 'pull_request' + uses: actions/github-script@v7 + with: + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: '❌ **Code formatting issue detected**\n\nYour code needs to be formatted with Prettier. Please run `npx prettier --write .` locally and push the changes, or the maintainers will format it for you.' + }) + - name: Commit and push formatted code - if: steps.prettier-check.outputs.needs_formatting == 'true' + if: steps.prettier-check.outputs.needs_formatting == 'true' && github.event_name == 'push' run: | # Configure git user git config user.name "github-actions[bot]" From 342499f0349bee69557b570a260d1fb24ec1e75a Mon Sep 17 00:00:00 2001 From: Markus Tacker Date: Sun, 20 Jul 2025 22:09:50 +0200 Subject: [PATCH 11/11] fix: only commit to main --- .github/workflows/format.yaml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml index 3da17af..275d4c5 100644 --- a/.github/workflows/format.yaml +++ b/.github/workflows/format.yaml @@ -47,18 +47,6 @@ jobs: if: steps.prettier-check.outputs.needs_formatting == 'true' run: npx prettier --write . - - name: Comment on PR about formatting - if: steps.prettier-check.outputs.needs_formatting == 'true' && github.event_name == 'pull_request' - uses: actions/github-script@v7 - with: - script: | - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: '❌ **Code formatting issue detected**\n\nYour code needs to be formatted with Prettier. Please run `npx prettier --write .` locally and push the changes, or the maintainers will format it for you.' - }) - - name: Commit and push formatted code if: steps.prettier-check.outputs.needs_formatting == 'true' && github.event_name == 'push' run: |