diff --git a/.github/WORDLIST.txt b/.github/WORDLIST.txt new file mode 100644 index 0000000..e69de29 diff --git a/.github/workflows/auto-format.yml b/.github/workflows/auto-format.yml index 5c98340..556cc9e 100644 --- a/.github/workflows/auto-format.yml +++ b/.github/workflows/auto-format.yml @@ -3,44 +3,45 @@ name: auto-format on: workflow_dispatch: pull_request: + branches: [dev, main] -env: - GH_TOKEN: ${{ github.token }} +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true permissions: contents: write pull-requests: write -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - jobs: auto-format: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - if: github.event_name == 'pull_request' + - name: Generate a token + id: generate-token + uses: actions/create-github-app-token@v2 with: - fetch-depth: 0 - ref: ${{ github.head_ref }} - - uses: actions/checkout@v4 - if: github.event_name != 'pull_request' + app-id: ${{ vars.CCBR_BOT_APP_ID }} + private-key: ${{ secrets.CCBR_BOT_PRIVATE_KEY }} + owner: ${{ github.repository_owner }} + + - uses: actions/checkout@v7 with: - fetch-depth: 0 - ref: ${{ github.ref_name }} + token: ${{ steps.generate-token.outputs.token }} + ref: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} - name: git config run: | - git config --global user.name "github-actions[bot]" - git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" - - - name: Format R code with air - uses: rstudio/shiny-workflows/format-r-code@v1 + git config --global user.name "CCBR-bot" + git config --global user.email "258092125+ccbr-bot@users.noreply.github.com" + - name: format + uses: pre-commit/action@v3.0.1 + continue-on-error: true - name: commit & push + if: ${{ github.event_name == 'pull_request' }} run: | git add . - git commit -m "ci: 🤖 auto-format" || echo "nothing to commit" + git commit -m "ci: 🤖 auto-format with pre-commit" || echo "nothing to commit" git push || echo "nothing to push" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c5f56e1..d3bacfe 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,15 +2,19 @@ name: tests on: push: - branches: [ main, dev ] + branches: [main, dev] pull_request: - branches: [ main, dev ] + branches: [main, dev] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: tests: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v7 - name: Parse environment.json and set Docker image id: docker_image diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..75390d2 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,52 @@ +default_install_hook_types: [pre-commit, commit-msg] +default_stages: [pre-commit] +exclude: | + (?x)( + ^.codeocean/| + ^environment/| + ^metadata/| + ^code/MOSuite| + ^code/SCWorkflow| + ^code/OMIX* + ) + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 + hooks: + - id: check-added-large-files + args: ["--maxkb=10240"] + - id: end-of-file-fixer + - id: trailing-whitespace + - id: check-json + # spell check + - repo: https://github.com/codespell-project/codespell + rev: v2.4.2 + hooks: + - id: codespell + args: + [ -I, .github/WORDLIST.txt ] + # R formatting + - repo: https://github.com/posit-dev/air-pre-commit + rev: 0.10.0 + hooks: + - id: air-format + - repo: https://github.com/lorenzwalthert/precommit + rev: v0.4.3.9028 + hooks: + - id: parsable-R + # Python formatting + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.15.16 + hooks: + - id: ruff-check + args: [--fix] + - id: ruff-format + + # enforce conventional commit format + - repo: https://github.com/compilerla/conventional-pre-commit + rev: v4.4.0 + hooks: + - id: conventional-pre-commit + stages: [commit-msg] + args: []