Skip to content

Commit

Permalink
Merge pull request #16 from robzr/add_actions
Browse files Browse the repository at this point in the history
Add GitHub actions
  • Loading branch information
robzr committed Mar 22, 2024
2 parents cc6a17a + 7d06470 commit 382a5e9
Show file tree
Hide file tree
Showing 5 changed files with 903 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .github/workflows/bin/embed_sver_in_action.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

cd "$(git rev-parse --show-toplevel)"
tmp=$(mktemp)
sed -n '1,/#action-sver-begin/p' action.yaml >"${tmp}"
sed 's/^/ /' sver >>"${tmp}"
sed -n '/#action-sver-end$/,$p' action.yaml >>"${tmp}"
mv "$tmp" action.yaml
85 changes: 85 additions & 0 deletions .github/workflows/test_action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Test Action

on:
pull_request:

jobs:
test:
name: Test Action
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true

- run: |
# test that action has current sver embedded
.github/workflows/bin/embed_sver_in_action.sh
if ! git diff --quiet action.yaml ; then
echo '::error title=Action not updated::The action /action.yaml' \
'was not updated with the current sver script.'
exit 1
fi
shell: bash
- id: sver-version
name: sver version
uses: ./
with:
command: version

- run: |
# test sver-version
if ! [[ '${{ steps.sver-version.outputs.output }}' =~ ^v[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]* ]] ; then
echo '::error title=Action returned invalid response::The action' \
'/action.yaml returned an invalid response' \
'(${{ steps.sver-version.outputs.output }})'
exit 1
fi
- id: sver-max
name: sver max
uses: ./
with:
command: max
input-command: git tag -l

- run: |
# test sver-max
if ! [[ '${{ steps.sver-max.outputs.output }}' =~ ^v[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]* ]] ; then
echo '::error title=Action returned invalid response::The action' \
'/action.yaml returned an invalid response' \
'(${{ steps.sver-max.outputs.output }})'
exit 1
fi
- id: sver-equals-true
name: sver equals (true)
uses: ./
with:
command: equals v1.2.3 v1.2.3+build-is-ignored

- run: |
# test sver-equals-true
if [ '${{ steps.sver-equals-true.outputs.output }}' != 'true' ] ; then
echo '::error title=Action returned invalid response::The action' \
'/action.yaml returned an invalid response' \
'(${{ steps.sver-equals-true.outputs.output }})'
exit 1
fi
- id: sver-equals-false
name: sver equals (false)
uses: ./
with:
command: equals v1.2.3 v1.2.3-pre.is.not.ignored

- run: |
# test sver-equals-false
if [ '${{ steps.sver-equals-false.outputs.output }}' != 'false' ] ; then
echo '::error title=Action returned invalid response::The action' \
'/action.yaml returned an invalid response' \
'(${{ steps.sver-equals-false.outputs.output }})'
exit 1
fi
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ can be even used as a function library in Busybox Dash/Ash.
- always checked with [shellcheck](https://github.com/koalaman/shellcheck) static analysis tool
- comprehensive [test](tests) coverage
- compatible with Bash v3 for us poor macOS users
- includes a GitHub Action

## Usage
### Installation
Expand Down Expand Up @@ -117,6 +118,61 @@ Constraints:
Examples: "~> v1.2, != 1.3", "> 1, <= v2.5, != v2.4.4", "v1, !pre"
```

### GitHub Action
A GitHub composite action is included in the repo, and each version of sver
is also embedded directly in the composite action, which makes it very quick
to load and run. Usage is simple, with the `command` input taking all commands
and arguments that the CLI does.
```yaml
- uses: robzr/sver@v1
with:
command: version
```
The `output` output will contain the result, regardless of type (string,
boolean, JSON, YAML).
```yaml
- id: sver
uses: robzr/sver@v1
with:
command: version
- if: steps.sver.outputs.output == 'v1.2.3'
...
```
Commands that return a boolean will return a boolean-as-string.
```yaml
- id: sver
uses: robzr/sver@v1
with:
command: constraint "${VERSION}" '~> v1.0, !pre'
- if: steps.sver.outputs.output == 'true'
...
```
For commands that take input on stdin, like `filter`, `max`, `min`, or `sort`,
the `input` input can be specified.
```yaml
- id: sver
uses: robzr/sver@v1
with:
command: max
input: |
v1.0.1
v2.2.2
...
- if: steps.sver.outputs.output == env.VERSION
...
```
The `input-command` input is also available, and will run the provided command,
and use the command's output as input for **sver**.
```yaml
- uses: robzr/sver@v1
with:
command: max '< v1, !pre'
input-command: git tag -l
```

### Bash function library
To use **sver** as a Bash function library, source it with the `SVER_RUN=false`
variable set.
Expand Down
Loading

0 comments on commit 382a5e9

Please sign in to comment.