From d463d1c2aa8e419b0c982d48c63851a411672fc5 Mon Sep 17 00:00:00 2001 From: Samuel Therrien Date: Tue, 19 Nov 2024 13:11:13 -0500 Subject: [PATCH] Split autofixes into its own workflow --- .github/workflows/canopeum_backend_deploy.yml | 4 +- .../canopeum_backend_pr_validation.yml | 24 +--------- .../workflows/canopeum_frontend_deploy.yml | 2 +- .../canopeum_frontend_pr_validation.yml | 19 +------- .github/workflows/pr_autofixes.yml | 47 +++++++++++++++++++ 5 files changed, 54 insertions(+), 42 deletions(-) create mode 100644 .github/workflows/pr_autofixes.yml diff --git a/.github/workflows/canopeum_backend_deploy.yml b/.github/workflows/canopeum_backend_deploy.yml index a3b37e4ac..97b4815f4 100644 --- a/.github/workflows/canopeum_backend_deploy.yml +++ b/.github/workflows/canopeum_backend_deploy.yml @@ -10,7 +10,7 @@ on: jobs: Build: - runs-on: "ubuntu-latest" + runs-on: ubuntu-latest defaults: run: working-directory: canopeum_backend @@ -18,7 +18,7 @@ jobs: fail-fast: false steps: - uses: actions/checkout@v4 - - name: 'login' + - name: login uses: docker/login-action@v1 with: registry: ghcr.io diff --git a/.github/workflows/canopeum_backend_pr_validation.yml b/.github/workflows/canopeum_backend_pr_validation.yml index 48a7e17d3..6c3be19de 100644 --- a/.github/workflows/canopeum_backend_pr_validation.yml +++ b/.github/workflows/canopeum_backend_pr_validation.yml @@ -64,34 +64,14 @@ jobs: python-version: "3.12" working-directory: canopeum_backend - Ruff-Autofixes: + Ruff: runs-on: unbuntu-latest defaults: run: working-directory: canopeum_backend - # Only run autofixes on PRs - if: ${{ github.event_name == 'pull_request' }} steps: - uses: actions/checkout@v4 - with: - repository: ${{ github.event.pull_request.head.repo.full_name }} - ref: ${{ github.event.pull_request.head.ref }} - # Token with Contents permissions to allow retriggering workflow - token: ${{ secrets.PR_AUTOFIX_PAT }} - - run: echo "${{github.event.head_commit.author.name}}" - uses: astral-sh/ruff-action@v1 - with: - args: check --fix - uses: astral-sh/ruff-action@v1 - # Format even on lint failure - if: ${{ !cancelled() }} - with: - args: format - - name: Commit autofixes - uses: EndBug/add-and-commit@v9 - # TODO: Prevent infinite loops, github.event.head_commit.author.name is not accessible in this context - # if: ${{ github.event.head_commit.author.name != 'github-actions' }} - # Push autofixes even on failure - if: ${{ !cancelled() }} with: - default_author: github_actions + args: format --check diff --git a/.github/workflows/canopeum_frontend_deploy.yml b/.github/workflows/canopeum_frontend_deploy.yml index ae929918b..1d1246a4a 100644 --- a/.github/workflows/canopeum_frontend_deploy.yml +++ b/.github/workflows/canopeum_frontend_deploy.yml @@ -21,7 +21,7 @@ jobs: run: npm ci - name: Build project run: npm run build - - name: 'login' + - name: login uses: docker/login-action@v1 with: registry: ghcr.io diff --git a/.github/workflows/canopeum_frontend_pr_validation.yml b/.github/workflows/canopeum_frontend_pr_validation.yml index 0fee30762..5ed354cb6 100644 --- a/.github/workflows/canopeum_frontend_pr_validation.yml +++ b/.github/workflows/canopeum_frontend_pr_validation.yml @@ -16,31 +16,16 @@ on: - ".github/workflows/canopeum_frontend_pr_validation.yml" jobs: - Lint-Autofixes: + Lint: runs-on: ubuntu-latest defaults: run: working-directory: canopeum_frontend - # Only run autofixes on PRs - if: ${{ github.event_name == 'pull_request' }} steps: - uses: actions/checkout@v4 - with: - repository: ${{ github.event.pull_request.head.repo.full_name }} - ref: ${{ github.event.pull_request.head.ref }} - # Token with Contents permissions to allow retriggering workflow - token: ${{ secrets.PR_AUTOFIX_PAT }} - uses: actions/setup-node@v4 - run: npm ci - - run: npm run lint:fix - - name: Commit autofixes - uses: EndBug/add-and-commit@v9 - # TODO: Prevent infinite loops, github.event.head_commit.author.name is not accessible in this context - # if: ${{ github.event.head_commit.author.name != 'github-actions' }} - # Push autofixes even on failure - if: ${{ !cancelled() }} - with: - default_author: github_actions + - run: npm run lint Build: runs-on: ubuntu-latest diff --git a/.github/workflows/pr_autofixes.yml b/.github/workflows/pr_autofixes.yml new file mode 100644 index 000000000..8ab3b0702 --- /dev/null +++ b/.github/workflows/pr_autofixes.yml @@ -0,0 +1,47 @@ +name: PR Autofixes + +on: + pull_request: + branches: + - main + +jobs: + Autofixes: + runs-on: unbuntu-latest + # Only run autofixes on PRs + if: ${{ github.event_name == 'pull_request' }} + steps: + - uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.event.pull_request.head.ref }} + # Token with Contents permissions to allow retriggering workflow + token: ${{ secrets.PR_AUTOFIX_PAT }} + + # Ruff autofixes + - run: cd canopeum_backend + - uses: astral-sh/ruff-action@v1 + # Fix even on other steps failure + if: ${{ !cancelled() }} + with: + args: check --fix + - uses: astral-sh/ruff-action@v1 + # Format even on lint failure + if: ${{ !cancelled() }} + with: + args: format + + # ESLint & Dprint autofixes + - run: cd ../canopeum_frontend + - run: npm run lint:fix + # Fix even on other steps failure + if: ${{ !cancelled() }} + + - name: Commit autofixes + uses: EndBug/add-and-commit@v9 + # TODO: Prevent infinite loops, github.event.head_commit.author.name is not accessible in this context + # if: ${{ github.event.head_commit.author.name != 'github-actions' }} + # Push autofixes even on failure + if: ${{ !cancelled() }} + with: + default_author: github_actions