Skip to content

Commit

Permalink
Release v1.0.0 | Core Release
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthri committed Jun 29, 2023
2 parents 1388aad + eeee6e9 commit 254c50b
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 47 deletions.
18 changes: 9 additions & 9 deletions .github/PULL_REQUEST_TEMPLATE/merge_request.md
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.
54 changes: 54 additions & 0 deletions .github/workflows/check-eol.yml
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.
17 changes: 0 additions & 17 deletions .github/workflows/reusable_workflow.yml

This file was deleted.

12 changes: 12 additions & 0 deletions .github/workflows/run-check-eol.yml
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
9 changes: 0 additions & 9 deletions .github/workflows/run_reusable_workflow.yml

This file was deleted.

File renamed without changes.
40 changes: 31 additions & 9 deletions README.md
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.
61 changes: 58 additions & 3 deletions docs/Test_List.md
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.
2 changes: 2 additions & 0 deletions test/respects_gitattributes/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lf.txt text eol=lf
crlf.txt text eol=crlf
1 change: 1 addition & 0 deletions test/respects_gitattributes/crlf.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions test/respects_gitattributes/lf.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit 254c50b

Please sign in to comment.