Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
dvershinin committed Apr 26, 2023
1 parent c9b4c4a commit 63f4217
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 4 deletions.
99 changes: 99 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,100 @@
# lastversion-action

This GitHub Action uses the `lastversion` command-line utility to fetch the latest stable version of any GitHub project
or other software.

## Inputs

### `repository`
**Required**. The GitHub repository or the name of the software for which you want to fetch the latest stable version.
Example: nginx or https://github.com/mautic/mautic.

### `branch`
Optional. The branch to fetch the latest version from. Default is no branch filtering. Example: mainline.

### `output_format`
Optional. The output format for the results. Allowed values are: version, json, and assets. Default is version.

### `extra_args`
Optional. Any extra arguments to pass to the lastversion utility.

## Outputs

### `last_version`

The latest stable version of the specified software or GitHub project. Or any other output, depending on the
`output_format` input.

## Usage

You can do a lot of useful things, but the primary use cases are:

* Download and extract the latest stable version of some software in your GitHub workflow
* Simply get the latest version string of some software for use in your GitHub workflow

### Downloading the latest stable version of software

To use this action in your GitHub workflow, add the following step:

```yaml
jobs:
hello_world_job:
runs-on: ubuntu-latest
name: A job to say hello
steps:
- name: Download stable NGINX
uses: dvershinin/lastversion-action@main
with:
repository: 'nginx'
action: 'unzip'
branch: 'stable'
- name: What do we have here
run: ls -al
```
At this point in your GitHub workflow, you have the latest stable version of NGINX downloaded and extracted in the
current directory.
### Getting the latest version string of some software
```yaml
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Fetch latest version
id: lastversion
uses: dvershinin/lastversion-action@main
with:
repository: 'nginx'
branch: 'mainline'
output_format: 'version'

- name: Print latest version
run: echo "Latest version is ${{ steps.lastversion.outputs.last_version }}"
```
In this example, the `Fetch latest version` step will fetch the latest version of Nginx from the mainline branch, and
the `Print latest version` step will print the fetched version. You can adjust the inputs to fetch the latest version
of other software or GitHub projects.

#### Example with GitHub repository

```yaml
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Fetch latest version of Mautic
id: lastversion
uses: dvershinin/lastversion-action@main
with:
repository: 'https://github.com/mautic/mautic'
output_format: 'version'
- name: Print latest version
run: echo "Latest version of Mautic is ${{ steps.lastversion.outputs.last_version }}"
```

In this example, the `Fetch latest version of Mautic` step will fetch the latest stable version of the Mautic project,
and the `Print latest version` step will print the fetched version.
12 changes: 8 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ format=""
action=""
repository=""
branch=""
extra_args=""
github_token=""

# Parse the named arguments
Expand All @@ -26,6 +27,11 @@ while [ "$#" -gt 0 ]; do
repository="$2"
shift 2
;;
--extra_args)
extra_args="$2"
shift 2
;;
# other arguments ...
--github_token)
github_token="$2"
shift 2
Expand All @@ -37,16 +43,14 @@ while [ "$#" -gt 0 ]; do
esac
done

echo $GITHUB_TOKEN

# Set the GITHUB_TOKEN environment variable
export GITHUB_TOKEN="$github_token"

# Run the lastversion command with the given inputs
if [ -z "$branch" ]; then
result=$(lastversion --verbose --format "$format" "$action" "$repository")
result=$(lastversion $extra_args --format "$format" "$action" "$repository")
else
result=$(lastversion --verbose --branch "$branch" --format "$format" "$action" "$repository")
result=$(lastversion $extra_args --branch "$branch" --format "$format" "$action" "$repository")
fi

# Set the result as an output variable
Expand Down

0 comments on commit 63f4217

Please sign in to comment.