-
Notifications
You must be signed in to change notification settings - Fork 2
44 lines (39 loc) · 1.27 KB
/
check_code.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
name: Lint & Format Code
on:
workflow_dispatch: ~
push:
paths:
- "**/*.js"
branches:
- "master"
- "dev"
jobs:
Format-Code:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 14
- name: Install dependencies
run: npm install
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- name: Format code
run: npx prettier --write "**/*.js"
- run: git config --global user.name "github-actions"
- run: git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
- run: git checkout -- package-lock.json
- run: git stash
- run: git checkout ${{ steps.extract_branch.outputs.branch }} && git pull
- run: git stash pop || true
- name: Commit code changes
run: "git add -u && git commit -m 'style: format code [skip ci]' || true"
- name: Push code changes
run: git push --set-upstream --force origin ${{ steps.extract_branch.outputs.branch }}