Skip to content

Commit 5ceca8f

Browse files
update github repo
1 parent 60c0b65 commit 5ceca8f

File tree

7 files changed

+182
-11
lines changed

7 files changed

+182
-11
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
on:
2+
pull_request:
3+
types: [closed]
4+
5+
jobs:
6+
update:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
project-name: [upload-github-repo]
11+
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
- uses: ./update-github-repo
16+
with:
17+
bucket-name: free-code-coverage
18+
project-name: ${{ matrix.project-name }}
19+
env:
20+
GITHUB_TOKEN: ${{ secrets.PAT }}

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,10 @@ Please refer to the related README for more details:
6868
- All code coverage data will be publicly available
6969
- persistence: Public GitHub repository
7070
- reporter: Separate commit status
71+
- [update-github-repo](./update-github-repo/README.md)
72+
- description:
73+
- Identical to `update`, but totally free of charge
74+
- Uses a public GitHub repository to persist data instead of an AWS S3 bucket
75+
- All code coverage data will be publicly available
76+
- persistence: Public GitHub repository
77+
- reporter: Separate commit status

update-github-repo.Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM python:3.8-alpine
2+
3+
ENV AWSCLI_VERSION='1.19.105'
4+
5+
RUN apk add --no-cache bash bc curl jq
6+
RUN pip install --quiet --no-cache-dir awscli==${AWSCLI_VERSION}
7+
8+
COPY update-github-repo/entrypoint.sh /entrypoint.sh
9+
COPY shared /shared
10+
ENTRYPOINT ["/entrypoint.sh"]

update-github-repo/README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# free-code-coverage (UPDATE-GITHUB-REPO)
2+
3+
- This action uses a public GitHub repository to persist code coverage data between runs.
4+
- This is a truly free of charge alternative to the default one using an AWS S3 bucket.
5+
- Downside is that all code coverage data must be public to allow badges to be read.
6+
7+
## Sample Usage
8+
9+
```
10+
on:
11+
pull_request:
12+
types: [labeled, unlabeled, closed]
13+
14+
jobs:
15+
update:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: SamuelCabralCruz/free-code-coverage/[email protected]
20+
with:
21+
github-repo: <github-repo>
22+
project-name: <project-name>
23+
env:
24+
GITHUB_TOKEN: ${{ secrets.PAT }}
25+
```
26+
> This can easily be adapted using a matrix strategy when using the action for multiple projects inside same repository.
27+
28+
### Environment Variables
29+
30+
- GITHUB_TOKEN
31+
- Personal Access Token (PAT) which has read/write access to both repository this action is used in and
32+
the public repository used to persist code coverage data.
33+
> Need to enable all repo rights
34+
35+
### Inputs
36+
37+
- github-repo
38+
- Public GitHub repository name following the following format {owner}/{repo}
39+
used to persist code coverage data between runs.
40+
- project-name
41+
- Lower kebab case string (lower-kebab-case-string) allowing to store action's data from multiple
42+
projects/repositories without collisions in the same bucket.
43+
- bypass-label (optional - default: 'ignoreCoverage')
44+
- Label to be added to a pull request in order to bypass code coverage check.
45+
- This label might be useful to knowingly accept a decrease in coverage.
46+
- Make sure that if a custom value is used for the UPLOAD part, it is the same value provided here.
47+
48+
## Badges
49+
50+
To add badges to your `README` or any other Markdown file, you can simply copy/paste and fill in the template below:
51+
```md
52+
![](https://raw.githubusercontent.com/<github-repo>/<branch-name>/badge-<project-name>-<escaped-branch-name>.svg)
53+
```
54+
- You will need to provide values for:
55+
- github-repo
56+
- project-name
57+
- branch-name
58+
- escaped-branch-name
59+
- For encoding reasons, need to replace any `/` by `-` in the branch name
60+
- Would normally be the name of your repository's default branch name `main` or `master`.
61+
- Could also be the name of a branch that is never destined to be closed (ex: `develop` if you use
62+
[Gitflow workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow)).
63+
64+
## Checks
65+
66+
To enforce code coverage not to decrease, you simply have to modify your branch rules and add
67+
`Code Coverage - <project-name>` as a required check before merge.

update-github-repo/action.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: 'Free Code Coverage - UPDATE-GITHUB-REPO'
2+
description: 'Update code coverage data when pull request is labeled, unlabeled, and closed'
3+
inputs:
4+
github-repo:
5+
description:
6+
'Public GitHub repository name following the following format {owner}/{repo}
7+
used to persist code coverage data between runs.'
8+
required: true
9+
project-name:
10+
description:
11+
"Lower kebab case string (lower-kebab-case-string) allowing to store action's data from multiple
12+
projects/repositories without collisions in the same bucket."
13+
required: true
14+
bypass-label:
15+
description:
16+
'Label to be added to a pull request in order to bypass code coverage check.
17+
This label might be useful to knowingly accept a decrease in coverage.
18+
Make sure that if a custom value is used for the UPLOAD part, it is the same value provided here.'
19+
required: false
20+
default: 'ignoreCoverage'
21+
runs:
22+
using: 'docker'
23+
image: '../update-github-repo.Dockerfile'
24+
args:
25+
- ${{ inputs.github-repo }}
26+
- ${{ inputs.project-name }}
27+
- ${{ inputs.bypass-label }}

update-github-repo/entrypoint.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
DIR="$(dirname "$0")"
4+
. "$DIR/shared/app.sh"
5+
. "$DIR/shared/validate.sh"
6+
. "$DIR/shared/update.sh"
7+
. "$DIR/shared/persistence/github.sh"
8+
. "$DIR/shared/reporter/commit_status.sh"
9+
10+
validate_pull_request_context "$GITHUB_EVENT_NAME"
11+
12+
GITHUB_REPO=$1
13+
PROJECT_NAME=$2
14+
BYPASS_LABEL=$3
15+
16+
BASE_BRANCH_NAME=$(jq -r '.pull_request.base.ref' "$GITHUB_EVENT_PATH" | tr '/' '-')
17+
BRANCH_NAME=$(jq -r '.pull_request.head.ref' "$GITHUB_EVENT_PATH" | tr '/' '-')
18+
EVENT_TYPE=$(jq -r '.action' "$GITHUB_EVENT_PATH")
19+
HAS_BYPASS_LABEL=$(jq ".pull_request | any(.labels[]; .name == \"$BYPASS_LABEL\")" "$GITHUB_EVENT_PATH")
20+
IS_MERGED=$(jq -r '.pull_request.merged' "$GITHUB_EVENT_PATH")
21+
STATUSES_URL=$(jq -r '.pull_request.statuses_url' "$GITHUB_EVENT_PATH")
22+
23+
set_up_persistence "$GITHUB_TOKEN" "$GITHUB_REPO"
24+
set_up_reporter "$GITHUB_TOKEN" "$STATUSES_URL" "$PROJECT_NAME"
25+
26+
validate_project_name "$PROJECT_NAME"
27+
28+
if [[ $EVENT_TYPE == 'closed' ]]; then
29+
on_pull_request_closed "$PROJECT_NAME" "$BRANCH_NAME" "$BASE_BRANCH_NAME" "$IS_MERGED"
30+
elif [[ $EVENT_TYPE =~ ^(labeled|unlabeled)$ ]]; then
31+
on_pull_request_labeled "$PROJECT_NAME" "$BRANCH_NAME" "$BASE_BRANCH_NAME" "$HAS_BYPASS_LABEL"
32+
else
33+
echo 'This action is designed to be run with pull_request event types: unlabeled, labeled, and closed. Quitting.'
34+
exit 1
35+
fi
36+
37+
tear_down_reporter
38+
tear_down_persistence

upload-github-repo/README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- This action uses a public GitHub repository to persist code coverage data between runs.
44
- This is a truly free of charge alternative to the default one using an AWS S3 bucket.
5+
- Downside is that all code coverage data must be public to allow badges to be read.
56

67
## Sample Usage
78

@@ -12,11 +13,11 @@ on: [pull_request]
1213
1314
- uses: SamuelCabralCruz/free-code-coverage/[email protected]
1415
with:
15-
bucket-name: <bucket-name>
16+
github-repo: <github-repo>
1617
project-name: <project-name>
1718
coverage-metric: <coverage-metric>
1819
env:
19-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20+
GITHUB_TOKEN: ${{ secrets.PAT }}
2021
```
2122

2223
### Environment Variables
@@ -60,16 +61,17 @@ on: [pull_request]
6061

6162
To add badges to your `README` or any other Markdown file, you can simply copy/paste and fill in the template below:
6263
```md
63-
![](https://<bucket-name>.s3.amazonaws.com/badge-<project-name>-<branch-name>.svg)
64+
![](https://raw.githubusercontent.com/<github-repo>/<branch-name>/badge-<project-name>-<escaped-branch-name>.svg)
6465
```
65-
- You will need to provide values for:
66-
- bucket-name
67-
- project-name
68-
- branch-name
69-
- For encoding reasons, need to replace any `/` by `-` in the branch name
70-
- Would normally be the name of your repository's default branch name `main` or `master`.
71-
- Could also be the name of a branch that is never destined to be closed (ex: `develop` if you use
72-
[Gitflow workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow)).
66+
- You will need to provide values for:
67+
- github-repo
68+
- project-name
69+
- branch-name
70+
- escaped-branch-name
71+
- For encoding reasons, need to replace any `/` by `-` in the branch name
72+
- Would normally be the name of your repository's default branch name `main` or `master`.
73+
- Could also be the name of a branch that is never destined to be closed (ex: `develop` if you use
74+
[Gitflow workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow)).
7375

7476
## Checks
7577

0 commit comments

Comments
 (0)