Skip to content

Commit

Permalink
Merge pull request #3 from straw-hat-team/add-asdf-get-all-versions
Browse files Browse the repository at this point in the history
feat: add asdf get versions
  • Loading branch information
yordis authored Nov 27, 2022
2 parents 59d5b6e + a8a6399 commit 1d5dfec
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
34 changes: 34 additions & 0 deletions asdf/get-versions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# ASDF Get Versions

Returns the versions from the .tool-versions file managed by asdf.

- [How-to Guides](#how-to-guides)

## Explanations

This action will return all the version from the .tool-versions file managed by
asdf as a JSON string where the key is the package name and the value is the
version.

## How-to Guides

### Get Started

1. Make sure `actions/checkout` action is used before this action.
2. Add this action to your job in your workflow, here is an example:

```yml
#...
jobs:
something:
name: Setup NodeJS
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2 # checkout the repository first
- uses: straw-hat-team/github-actions-workflows/asdf/git-versions@master
id: asdf-versions
- shell: sh
run: |
# Notice that the output is a JSON string
echo ${{ fromJSON(steps.asdf-versions.outputs.versions).nodejs }}
```
34 changes: 34 additions & 0 deletions asdf/get-versions/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: ASDF Get Versions
description: Returns the versions from the .tool-versions file managed by asdf
author: Straw Hat Team

inputs:
version-file:
description: The path to the .tool-versions file
required: false
default: .tool-versions

outputs:
versions:
description: "The versions from the .tool-versions file as a JSON string"
value: ${{ steps.get-versions.outputs.versions }}

runs:
using: composite
steps:
- name: Get the versions from the .tool-versions file
shell: bash
id: get-versions
run: |
TOOL_VERSIONS_FILE_PATH=${{ inputs.version-file }}
if [ ! -f $TOOL_VERSIONS_FILE_PATH ]; then
echo "\033[0;31m.tool-versions file not found"
exit 1
fi
VERSIONS=()
while read -r line; do
read -r package version <<< "$line"
echo "found package: '$package' with version: '$version'"
VERSIONS+=("\"$package\": \"$version\"")
done < $TOOL_VERSIONS_FILE_PATH
echo "versions={$(IFS=,; echo "${VERSIONS[*]}")}" >> $GITHUB_OUTPUT

0 comments on commit 1d5dfec

Please sign in to comment.