Skip to content

Commit

Permalink
Updates with latest test results (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajbos authored Jun 5, 2023
1 parent e8fc4f6 commit 8122ee0
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 12 deletions.
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,65 @@
# actionlint
Action wrapper for [rhysd/actionlint](https://github.com/rhysd/actionlint) to make using it easier.

This action will run your repository through actionlint and detect common errors like:
- Calling an `output` or `needs` object that has not been defined
- Run shell check on all `run` commands
- And more, check the [actionlint documentation](https://github.com/rhysd/actionlint) for more information

## Results
If there are no errors from actionlint, this action will succeed. If there are errors, this action will fail and output the errors in the logs.

If running in a Pull Request context, then the action will also annotate the **changed** files with the errors. This is useful to see what errors were introduced by the Pull Request. Note: this only works if you include the `pull-requests: write` permission in your workflow file.

## Usage:
```yaml
jobs:
run-actionlint:
runs-on: ubuntu-latest
permissions:
# needed for the checkout action
contents: read
# needed to annotate the files in a pull request with comments
pull-requests: write
steps:
# checkout the source code to analyze
- uses: actions/checkout@v3 # v3

# run the actionlinter, will fail on errors
- uses: devops-actions/actionlint@v0.1.0
```
## Usage with results file:
If you want to pick up the results file and use its contents somewhere else, then use it as follows:
```yaml
on:
push:

workflow_dispatch:

permissions:
contents: read
pull-requests: write

jobs:
job-1:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: devops-actions/actionlint@v0.1.0
continue-on-error: true
id: action-lint

- uses: actions/upload-artifact@v3
with:
name: actionlint-results
path: ${{ steps.action-lint.outputs.results-file }}
```
# Errors
## No projec was found in any parent directories
Error message: `no project was found in any parent directories of ".". check workflows directory is put correctly in your Git repository`
Solution: Add a `uses: actions/checkout@v3 # v3` to your workflow file, so the repository can be analyzed


39 changes: 27 additions & 12 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,49 @@ outputs:
runs:
using: composite
steps:
- name: Add annotation matcher for Action Lint to annotate the PR if needed
run: echo "::add-matcher::$GITHUB_ACTION_PATH/actionlint-matcher.json"
shell: bash

- name: Docker run
- name: Docker run rhysd/actionlint
shell: bash
id: run
env:
FAILONERRORS: ${{ inputs.fail-on-errors }}
run: |
# running version 1.6.22 of rhysd/actionlint
# execute rhysd/actionlint as a docker container
# disable pipefail -e -o that is set on the shell script from the runner to prevent exiting when the docker run command fails
set +e +o pipefail;
echo "Workspace: [$GITHUB_WORKSPACE]"
echo "GitHub Action path: [$GITHUB_ACTION_PATH]"
result=$(docker run -v $GITHUB_WORKSPACE:/repo --workdir /repo rhysd/actionlint@sha256:5f957b2a08d223e48133e1a914ed046bea12e578fe2f6ae4de47fdbe691a2468 -color -format "{{json .}}")
# matcher needed to annotate the PR with comments
echo "::add-matcher::$GITHUB_ACTION_PATH/actionlint-matcher.json"
actionLintContainer=rhysd/actionlint@sha256:5f957b2a08d223e48133e1a914ed046bea12e578fe2f6ae4de47fdbe691a2468 # 1.6.22
# run again to get a json result
result=$(docker run -v $GITHUB_WORKSPACE:/repo --workdir /repo $actionLintContainer -color -format "{{json .}}")
status=$?
echo $result > "actionlint-errors.json"
echo "resultsfile=actionlint-errors.json" >> $GITHUB_OUTPUT
if jq -e . >/dev/null 2>&1 <<<"$result"; then
echo "Parsed JSON result successfully"
else
echo "Failed to parse JSON, or got false/null"
if [[ $result -ne 'no project was found in any parent directories of ".". check workflows directory is put correctly in your Git repository' ]]; then
echo "Showing the resulting messages:"
echo $result
echo "-------------------------------"
fi
fi
echo $result>"actionlint-errors.json"
echo "resultsfile=actionlint-errors.json">>$GITHUB_OUTPUT
if [[ $status == 0 ]];
then
echo "Actionlint had no errors"
else
echo "Actionlint found errors"
if [[ $FAILONERRORS == "true" ]]; then
echo "Running the docker container directly to show the errors"
docker run -v $GITHUB_WORKSPACE:/repo --workdir /repo $actionLintContainer -color
fi
fi
if [[ $FAILONERRORS == "true" ]];
Expand Down

0 comments on commit 8122ee0

Please sign in to comment.