From 1d9ff27af7916fda10bc57fa1497bbe468cadf65 Mon Sep 17 00:00:00 2001 From: Lam Chau Date: Thu, 5 Sep 2024 12:30:45 -0700 Subject: [PATCH] fix: simplify lint and format workflow (#372) --- .github/workflows/format.yml | 62 ----------------------------- .github/workflows/lint.yml | 45 --------------------- .github/workflows/trigger-lint.yml | 19 --------- .github/workflows/validate-json.yml | 26 ++++++++++++ Justfile | 8 ++-- bin/.just-1.34.0.pkg | 1 + bin/just | 1 + hooks/pre-commit | 7 +--- 8 files changed, 32 insertions(+), 137 deletions(-) delete mode 100644 .github/workflows/format.yml delete mode 100644 .github/workflows/lint.yml delete mode 100644 .github/workflows/trigger-lint.yml create mode 100644 .github/workflows/validate-json.yml create mode 120000 bin/.just-1.34.0.pkg create mode 120000 bin/just diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml deleted file mode 100644 index 8546137e..00000000 --- a/.github/workflows/format.yml +++ /dev/null @@ -1,62 +0,0 @@ -name: format json files with `jq` -on: - push: - branches: - - main - -permissions: - contents: read - issues: write - pull-requests: write - -jobs: - format-json: - runs-on: ubuntu-latest - steps: - - name: checkout code - uses: actions/checkout@v4 - - - uses: cashapp/activate-hermit@v1 - name: setup hermit with `just` and `jq` - with: - cache: true - - - name: format json files - id: format-json - run: | - if just format; then - echo "format_failed=false" >> $GITHUB_ENV - else - echo "format_failed=true" >> $GITHUB_ENV - fi - - - name: check for changes - id: check-changes - run: | - if [ -n "$(git status --porcelain)" ]; then - echo "changes_detected=true" >> $GITHUB_ENV - else - echo "changes_detected=false" >> $GITHUB_ENV - fi - - - name: commit changes - if: env.changes_detected == 'true' - run: | - git config --local user.email "github-actions[bot]@users.noreply.github.com" - git config --local user.name "github-actions[bot]" - git add "**/*.json" - git commit --message "chore: format json files" - git push - - - name: create issue if formatting failed - if: failure() && env.format_failed == 'true' - uses: actions/github-script@v6 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - github.rest.issues.create({ - owner: context.repo.owner, - repo: context.repo.repo, - title: 'JSON Formatting Failed', - body: 'The automatic JSON formatting job failed. Please check the logs and fix the issues manually.' - }) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 1b10c6d9..00000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: lint json files with `jq` -on: - workflow_run: - workflows: ["run-linter"] - types: - - completed - -permissions: - contents: read - issues: write - pull-requests: write - -jobs: - lint-json: - runs-on: ubuntu-latest - steps: - - name: checkout code - uses: actions/checkout@v4 - - - uses: cashapp/activate-hermit@v1 - name: setup hermit with `just` and `jq` - with: - cache: true - - - name: lint json files - id: lint-json - run: | - if just lint; then - echo "lint_failed=false" >> $GITHUB_ENV - else - echo "lint_failed=true" >> $GITHUB_ENV - fi - - - name: add a comment to the pull request - if: env.lint_failed == 'true' - uses: actions/github-script@v4 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - github.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: "[error] linting failed. please fix the errors and push again." - }) diff --git a/.github/workflows/trigger-lint.yml b/.github/workflows/trigger-lint.yml deleted file mode 100644 index 646ff8bd..00000000 --- a/.github/workflows/trigger-lint.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: run-linter - -on: - push: - branches: - - "**" - -jobs: - trigger-lint: - runs-on: ubuntu-latest - steps: - - name: "[trigger]: run lint workflow" - run: | - curl \ - --request POST \ - --user "${{ secrets.GITHUB_TOKEN }}" \ - --header "Accept: application/vnd.github.v3+json" \ - --url "https://api.github.com/repos/TBD54566975/tbdex/actions/workflows/lint.yml/dispatches" \ - --data '{"ref": "main"}' diff --git a/.github/workflows/validate-json.yml b/.github/workflows/validate-json.yml new file mode 100644 index 00000000..1349c720 --- /dev/null +++ b/.github/workflows/validate-json.yml @@ -0,0 +1,26 @@ +name: validate-json +on: + push: + branches: + - "**" + + pull_request: + types: + - opened + - synchronize + +jobs: + format: + runs-on: ubuntu-latest + steps: + - name: checkout code + uses: actions/checkout@v4 + + - uses: cashapp/activate-hermit@v1 + name: setup hermit with `just` and `jq` + with: + cache: true + + - name: format json files + id: format-json + run: just format diff --git a/Justfile b/Justfile index ca0c13cc..5314b8de 100644 --- a/Justfile +++ b/Justfile @@ -31,17 +31,15 @@ lint: clean exit 1 fi - no_errors_found=true + has_errors=false for file in $(find hosted -type f -name "*.json"); do if ! jq empty $file > /dev/null; then printf "[error] %s is not a valid JSON file\n\n" $file - no_errors_found=false + has_errors=true fi done - if [ "$no_errors_found" = true ]; then - echo "[success] All JSON files are valid" - else + if [ "$has_errors" = true ]; then exit 1 fi diff --git a/bin/.just-1.34.0.pkg b/bin/.just-1.34.0.pkg new file mode 120000 index 00000000..383f4511 --- /dev/null +++ b/bin/.just-1.34.0.pkg @@ -0,0 +1 @@ +hermit \ No newline at end of file diff --git a/bin/just b/bin/just new file mode 120000 index 00000000..bf5e8a7c --- /dev/null +++ b/bin/just @@ -0,0 +1 @@ +.just-1.34.0.pkg \ No newline at end of file diff --git a/hooks/pre-commit b/hooks/pre-commit index 78770f53..591c471a 100644 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -1,8 +1,3 @@ #!/usr/bin/env bash -if just lint; then - echo "[success] linting passed" -else - echo "[error] linting failed" - exit 1 -fi +just format