Skip to content

Commit d52507b

Browse files
authored
Merge pull request #1596 from Adyen/fix/run-composite-formatting
refactor(ci): move formatting to a reusable action
2 parents e4f96fc + 6d47415 commit d52507b

2 files changed

Lines changed: 43 additions & 15 deletions

File tree

.github/actions/format/action.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: 'Format Node.js Code'
2+
description: 'Runs npm run lint:fix'
3+
inputs:
4+
path:
5+
description: 'Path to the node repository'
6+
default: '.'
7+
runs:
8+
using: 'composite'
9+
steps:
10+
- name: Set up Node.js and cache dependencies
11+
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
12+
with:
13+
node-version: 20.x
14+
cache: 'npm'
15+
cache-dependency-path: '${{ inputs.path }}/**/package-lock.json'
16+
17+
- name: Install dependencies
18+
run: npm ci --legacy-peer-deps
19+
shell: bash
20+
working-directory: ${{ inputs.path }}
21+
22+
- name: Run lint:fix
23+
run: npm run lint:fix
24+
shell: bash
25+
working-directory: ${{ inputs.path }}

.github/workflows/format.yml

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
1-
name: Node.js Format
1+
name: Format and Commit Code
22

33
on:
4-
push:
5-
branches:
6-
- 'sdk-automation/models'
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: write
78

89
jobs:
910
format:
10-
if: ${{ github.event.commits != null && !startsWith(github.event.head_commit.message, 'style(fmt)') }}
11-
permissions:
12-
contents: write
1311
runs-on: ubuntu-latest
1412
steps:
1513
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
1614
with:
1715
token: ${{ secrets.ADYEN_AUTOMATION_BOT_ACCESS_TOKEN }}
18-
- uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
16+
17+
- name: Format Code
18+
uses: ./.github/actions/format
1919
with:
20-
node-version: 20.x
21-
- run: |
22-
npm ci --legacy-peer-deps
23-
npm run lint:fix
24-
- run: |
20+
path: .
21+
22+
- name: Commit and Push Changes
23+
run: |
2524
git config user.name AdyenAutomationBot
2625
git config user.email "${{ secrets.ADYEN_AUTOMATION_BOT_EMAIL }}"
2726
git add .
28-
git commit -m "style(fmt): code formatted" || echo "No changes to commit"
29-
git push
27+
if ! git diff --staged --quiet; then
28+
git commit -m "style(fmt): code formatted"
29+
git push
30+
else
31+
echo "No changes to commit"
32+
fi

0 commit comments

Comments
 (0)