From 7734bc1b2464fdf9f713b514b79f2887372eb46b Mon Sep 17 00:00:00 2001 From: Girges Scandar <25529286+scandar@users.noreply.github.com> Date: Tue, 12 Nov 2024 14:47:07 +0100 Subject: [PATCH] checkout action repo (#6) * checkout action repo * update repo name * add id * update readme * rename input * fix docs --- .github/workflows/ci.yml | 2 +- README.md | 37 ++++++++++++++++--------------------- action.yml | 7 +++++-- src/main.test.ts | 2 +- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ff83515..a997bba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -95,7 +95,7 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} branch: "main" # use ${{ github.ref_name }} when using this on a real branch - fail-on-missing-codeowners: false + fail_on_missing_codeowners: false - name: Print Output id: output diff --git a/README.md b/README.md index edd28a4..d8c663f 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ owner, a comment is added to the PR with the list of orphan files. ### Inputs - `github_token`: String - Github Token (required) -- `fail-on-missing-codeowners`: Boolean - Fail CI if there are files without +- `fail_on_missing_codeowners`: Boolean - Fail CI if there are files without owners (default: true) - `codeowners_path`: String - Path to the codeowners file (default: CODEOWNERS) - `pr_number`: Number - Scan only the files modified in the PR (optional if @@ -83,18 +83,20 @@ permissions: jobs: check-codeowners: - name: Check CODEOWNERS runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Check CODEOWNERS + id: ownyourcode uses: getyourguide/ownyourcode@v1 with: github_token: ${{ secrets.GITHUB_TOKEN }} pr_number: ${{ github.event.number }} + + - name: Print Output + run: | + echo "${{ steps.ownyourcode.outputs.total_orphan_files }}" + echo "${{ steps.ownyourcode.outputs.total_scanned_files }}" + echo "${{ steps.ownyourcode.outputs.failed }}" ``` ### Using on a branch @@ -106,19 +108,17 @@ on: push: branches: - main + permissions: id-token: write contents: read pull-requests: write # we need this to write comments in PRs jobs: check-codeowners: - name: Check CODEOWNERS runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Test Local Action + - name: Check CODEOWNERS + id: ownyourcode uses: getyourguide/ownyourcode@v1 with: github_token: ${{ secrets.GITHUB_TOKEN }} @@ -131,26 +131,21 @@ jobs: --- jobs: check-codeowners: - name: Check CODEOWNERS runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Check CODEOWNERS id: ownyourcode uses: getyourguide/ownyourcode@v1 with: github_token: ${{ secrets.GITHUB_TOKEN }} - pr_number: ${{ github.event.number }} + branch: ${{ github.ref_name }} + fail_on_missing_codeowners: false # important for next step to work - name: Print Output - id: output run: | - echo "${{ steps.ownyourcode.outputs.total_orphan_files }}" - echo "${{ steps.ownyourcode.outputs.total_scanned_files }}" - echo "${{ steps.ownyourcode.outputs.failed }}" + echo "Total orphan files: ${{ steps.ownyourcode.outputs.total_orphan_files }}" + echo "Total scanned files: ${{ steps.ownyourcode.outputs.total_scanned_files }}" + echo "Failed: ${{ steps.ownyourcode.outputs.failed }}" ``` ## CODEOWNERS file diff --git a/action.yml b/action.yml index ebf53ec..60bae81 100644 --- a/action.yml +++ b/action.yml @@ -8,7 +8,7 @@ branding: color: "orange" inputs: - fail-on-missing-codeowners: + fail_on_missing_codeowners: description: "Fail CI if there are files without owners" default: "true" required: false @@ -43,6 +43,8 @@ runs: - name: Checkout id: checkout uses: actions/checkout@v4 + with: + repository: "getyourguide/ownyourcode" - name: Setup Node.js id: setup-node @@ -57,6 +59,7 @@ runs: run: npm ci - name: Check Codeowners + id: codeowners shell: bash run: node ./dist/index.js env: @@ -64,5 +67,5 @@ runs: INPUT_CODEOWNERS_PATH: ${{ inputs.codeowners_path }} INPUT_PR_NUMBER: ${{ inputs.pr_number }} INPUT_FAIL_ON_MISSING_CODEOWNERS: - ${{ inputs.fail-on-missing-codeowners }} + ${{ inputs.fail_on_missing_codeowners }} INPUT_BRANCH: ${{ inputs.branch }} diff --git a/src/main.test.ts b/src/main.test.ts index 8a20c86..153bb5e 100644 --- a/src/main.test.ts +++ b/src/main.test.ts @@ -135,7 +135,7 @@ describe("OwnYourCode - PR Mode", () => { ); }); - it("should not fail if files have no owners but fail-on-missing-codeowners input is false", async () => { + it("should not fail if files have no owners but fail_on_missing_codeowners input is false", async () => { inputs.FAIL_ON_MISSING_CODEOWNERS = "false"; vi.spyOn(PrHandler.prototype, "getCodeOwnersFile").mockResolvedValueOnce( "__FILE-CONTENT__",