-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from straw-hat-team/add-asdf-get-all-versions
feat: add asdf get versions
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |