Skip to content

Commit

Permalink
Feat: working_directory support (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
josecfreittas authored Jun 13, 2023
1 parent a2162ef commit 9227d8f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This action gets the output of `mix test --cover`, treats it, and creates a feed

By default, this action assumes that you are using Elixir's default coverage tool. However, it also supports [ExCoveralls](https://github.com/parroty/excoveralls), and if you prefer it, simply add the `coverage_tool` configuration inside the `with` option that specifies it.

Additionally, this action supports setting a `working_directory` as an input if your Elixir project is not at the root of the repository.

![image](https://user-images.githubusercontent.com/10376340/200857131-94cb2147-d703-4965-be5c-6cd6521826da.png#gh-light-mode-only)
![image](https://user-images.githubusercontent.com/10376340/200857627-8232b1de-fcbe-4b68-9f30-df2b89b61ccf.png#gh-dark-mode-only)

Expand Down Expand Up @@ -39,10 +41,10 @@ jobs:
- uses: actions/checkout@v3

- name: Setup Erlang and Elixir
uses: erlef/setup-beam@v1.13.1
uses: erlef/setup-beam@v1.15.4
with:
elixir-version: "1.14.1"
otp-version: "25.1.2"
elixir-version: "1.14.5-otp-26"
otp-version: "26.0"

- name: Mix and build cache
uses: actions/cache@v3
Expand All @@ -62,9 +64,10 @@ jobs:
mix compile --warnings-as-errors
- name: Tests & Coverage
uses: josecfreittas/elixir-coverage-feedback-action@v0.3.1
uses: josecfreittas/elixir-coverage-feedback-action@v0.4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
coverage_threshold: 80
# working_directory: ./your_project_directory
# coverage_tool: excoveralls
```
15 changes: 12 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,27 @@ inputs:
default: "default"
required: false
coverage_threshold:
description: Coverage threshold
description: "Coverage threshold"
default: 90
required: false
working_directory:
description: "Working directory"
default: "."
required: false

runs:
using: "composite"
steps:

- name: Tests and coverage
id: tests
shell: bash
run: if mix test --cover 2>&1 | tee coverage_report.log; then echo 'success running the tests'; fi
run: |
cd ${{ inputs.working_directory }}
if mix test --cover 2>&1 | tee coverage_report.log; then echo 'success running the tests'; fi
- name: Feedback comment
uses: actions/github-script@v6.1.0
uses: actions/github-script@v6.4.1
with:
github-token: ${{ inputs.github_token }}
script: |
Expand All @@ -42,4 +50,5 @@ runs:
context,
coverageTool,
coverageThreshold: ${{ inputs.coverage_threshold }},
workingDirectory: '${{ inputs.working_directory }}',
});
4 changes: 3 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ const maybeCreateOrUpdateComment = async ({ github, owner, repo, issueNumber, co
});
}

module.exports = async ({ core, actor, github, context, coverageTool, coverageThreshold }) => {
module.exports = async ({ core, actor, github, context, coverageTool, coverageThreshold, workingDirectory }) => {
const fs = require("fs");

process.chdir(workingDirectory);

const output = fs.readFileSync("./coverage_report.log", { encoding: "utf8", flag: "r" });
const outputParser = parsers[coverageTool] || parsers.default;
const data = outputParser(output);
Expand Down

0 comments on commit 9227d8f

Please sign in to comment.