generated from Arthri/reusable-workflow-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
168 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
## Description | ||
<!-- A list of what the merge request changes. --> | ||
|
||
## Intent | ||
<!-- A summary of why the merge request should be merged. --> | ||
|
||
## Additional Context | ||
<!-- Additional information such as motivation or inspiration. --> | ||
None. | ||
## Description | ||
<!-- A list of what the merge request changes. --> | ||
|
||
## Intent | ||
<!-- A summary of why the merge request should be merged. --> | ||
|
||
## Additional Context | ||
<!-- Additional information such as motivation or inspiration. --> | ||
None. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: Check End-of-Line Sequence | ||
run-name: Check End-of-Line Sequence | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
checkout-ref: | ||
description: Specifies the commitish to checkout. Defaults to $GITHUB_SHA. For more information, see <https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows>. | ||
required: false | ||
type: string | ||
default-eol: | ||
default: lf | ||
description: Specifies the default end-of-line sequence. The supported values are "lf"(default), "crlf", and "mixed". | ||
required: false | ||
type: string | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
jobs: | ||
check-eol: | ||
runs-on: ubuntu-22.04 | ||
timeout-minutes: 1 | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ inputs.checkout-ref }} | ||
|
||
- name: Check End-of-Line Sequence | ||
run: | | ||
exit_code=0 | ||
while IFS= read line; do | ||
if [[ $line =~ ^i/([^ ]*)\ +w/([^ ]*)\ +attr/([^[:space:]]+( eol=([[:alpha:]]+))?)?\ +$'\t'(.+)$ ]] ; then | ||
index_eol=${BASH_REMATCH[1]} | ||
working_tree_eol=${BASH_REMATCH[2]} | ||
expected_eol=${BASH_REMATCH[5]:-${{ inputs.default-eol }}} | ||
if { [ "$index_eol" == "lf" ] || [ "$index_eol" == "crlf" ] || [ "$index_eol" == "mixed" ] ; } && [ "$index_eol" != "$expected_eol" ] ; then | ||
echo "${BASH_REMATCH[6]}:"$'\t'"End-of-line sequence in index($index_eol) does not match expected end-of-line sequence $expected_eol." | ||
exit_code=1 | ||
elif { [ "$working_tree_eol" == "lf" ] || [ "$working_tree_eol" == "crlf" ] || [ "$working_tree_eol" == "mixed" ] ; } && [ "$working_tree_eol" != "$expected_eol" ] ; then | ||
echo "${BASH_REMATCH[6]}:"$'\t'"End-of-line sequence in working tree($working_tree_eol) does not match expected end-of-line sequence $expected_eol." | ||
exit_code=1 | ||
fi | ||
else | ||
echo 'Unable to match '"$line" | ||
exit_code=1 | ||
fi | ||
done < <(git ls-files --eol) | ||
exit $exit_code |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: Check End-of-Line Sequence | ||
run-name: Check End-of-Line Sequence | ||
|
||
on: | ||
push: | ||
branches: [ master, dev ] | ||
pull_request: | ||
branches: [ master, dev ] | ||
|
||
jobs: | ||
check-eol: | ||
uses: ./.github/workflows/check-eol.yml |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,44 @@ | ||
# reusable-workflow | ||
A reusable workflow for doing x, y, and z. | ||
A linter for end-of-line sequences based on .gitattributes. | ||
|
||
## Installation | ||
Add a new workflow under `.github/workflows/` with the following contents. | ||
```yml | ||
name: New Reusable Workflow | ||
run-name: New Reusable Workflow | ||
name: Check End-of-Line Sequence | ||
run-name: Check End-of-Line Sequence | ||
|
||
on: | ||
push: | ||
branches: [ master, dev ] | ||
pull_request: | ||
branches: [ master, dev ] | ||
|
||
jobs: | ||
reusable-workflow: | ||
uses: Arthri/reusable-workflow/.github/workflows/reusable-workflow.yml@v1 | ||
|
||
check-eol: | ||
uses: Arthri/check-eol/.github/workflows/check-eol.yml@v1 | ||
``` | ||
|
||
## Usage | ||
1. Do this. | ||
1. Do that. | ||
1. This happens. | ||
|
||
### Default End-of-Line Sequence | ||
The workflow uses `LF` as the fallback end-of-line sequence. The default end-of-line sequence can be configured either through [`.gitattributes`](https://www.git-scm.com/docs/gitattributes) or through the parameter `default-eol`. The following example sets the fallback end-of-line sequence to `CRLF`. | ||
```yml | ||
jobs: | ||
check-eol: | ||
uses: Arthri/check-eol/.github/workflows/check-eol.yml@v1 | ||
with: | ||
default-eol: crlf | ||
``` | ||
|
||
### Checkout Ref | ||
`$GITHUB_SHA` is used by [`actions/checkout@v3`](https://github.com/actions/checkout/tree/v3) as the default commitish to checkout. The following example sets `dev` as the ref to checkout. | ||
```yml | ||
jobs: | ||
check-eol: | ||
uses: Arthri/check-eol/.github/workflows/check-eol.yml@v1 | ||
with: | ||
checkout-ref: dev | ||
``` | ||
|
||
### More Events | ||
The reusable workflow is not limited to pushes and pull requests, other types of events such as releases are also supported. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,66 @@ | ||
# Test List | ||
A list of steps for testing the workflow's features. | ||
|
||
## Action fails randomly | ||
## Action successfully identifies non-compliant files | ||
|
||
### Steps | ||
1. Push to GitHub. | ||
1. Create the following files, | ||
- `lf-lf.txt` - A file containing one LF. | ||
- `lf-crlf.txt` - A file containing one CRLF. | ||
- `lf-mixed.txt` - A file containing one LF and one CRLF. | ||
- `crlf-lf.txt` - A file containing one LF. | ||
- `crlf-crlf.txt` - A file containing one CRLF. | ||
- `crlf-mixed.txt` - A file containing one LF and one CRLF. | ||
1. Create or copy a binary file, such as an image or an archive. | ||
1. Run the command `git config core.autocrlf false` | ||
1. Create a file named `.gitattributes` with the following contents, | ||
```ini | ||
lf-*.txt text eol=lf | ||
crlf-*.txt text eol=crlf | ||
``` | ||
1. All other files created such as `.gitattributes` and workflow files must be using the LF end-of-line sequence. | ||
1. Commit and push to GitHub. | ||
|
||
### Outputs | ||
1. Workflow triggers. | ||
1. Workflow fails randomly. | ||
1. Workflow fails. | ||
1. The workflow should flag the following files, | ||
- `lf-crlf.txt`. | ||
- `lf-mixed.txt`. | ||
- `crlf-lf.txt`. | ||
- `crlf-mixed.txt`. | ||
1. The workflow should not flag the following files, | ||
- `lf-lf.txt`. | ||
- `crlf-crlf.txt`. | ||
- The binary file. | ||
|
||
## Action respects `.gitattributes` | ||
|
||
### Steps | ||
1. Replace the contents of the file named `.gitattributes` with the following, | ||
```ini | ||
*-lf.txt text eol=lf | ||
*-crlf.txt text eol=crlf | ||
``` | ||
1. Remove the files ending in `mixed`. | ||
1. Commit and push to GitHub. | ||
|
||
### Outputs | ||
1. Workflow triggers. | ||
1. Workflow succeeds. | ||
|
||
## Action succeeds when non-compliant files are fixed | ||
|
||
### Steps | ||
1. Replace the contents of the file named `.gitattributes` with the following, | ||
```ini | ||
lf-*.txt text eol=lf | ||
crlf-*.txt text eol=crlf | ||
``` | ||
1. Restore the files ending in `mixed`. | ||
1. Replace all non-LF end-of-line sequences with LF in files starting with `lf-*`. | ||
1. Replace all non-CRLF end-of-line sequences with CRLF in files starting with `crlf-*`. | ||
|
||
### Outputs | ||
1. Workflow triggers. | ||
1. Workflow succeeds. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
lf.txt text eol=lf | ||
crlf.txt text eol=crlf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|