Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup ecm-distro-tools GitHub Action #267

Merged
merged 20 commits into from
Oct 5, 2023
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,29 @@ docker run --rm -it --env GITHUB_TOKEN=<TOKEN> rancher/ecm-distro-tools tag_rke2

See seperate [documentation](./docs/test_pad.md) for test-pad tool.

## GitHub action

This repository provides the "Setup ecm-distro-tools" GitHub action.
It downloads the assets belonging to the specified release to a temporary directory,
and adds the directory to the `PATH`.

### Usage

The action can be run on ubuntu-latest runners.
The `version` parameter is required.

brooksn marked this conversation as resolved.
Show resolved Hide resolved
```yaml
steps:
- name: setup ecm-distro-tools
uses: rancher/ecm-distro-tools
with:
version: v0.23.0
env:
GH_TOKEN: ${{ github.token }}
- name: release notes
run: gen_release_notes -h
```

## Contributing

We welcome additions to this repo and are excited to keep expanding its functionality.
Expand Down
34 changes: 34 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: 'Setup ecm-distro-tools'
description: 'Installs ecm-distro-tools scripts to the PATH.'
inputs:
version:
description: 'The tag of the ecm-distro-tools release to install.'
required: true
runs:
using: 'composite'
steps:
- shell: bash
run: |
TAG="${{ inputs.version }}"
brooksn marked this conversation as resolved.
Show resolved Hide resolved
REPO="rancher/ecm-distro-tools"
DOWNLOAD_DIR="$RUNNER_TEMP/ecm-distro-tools"
mkdir -p "$DOWNLOAD_DIR"
echo "$DOWNLOAD_DIR" >> "$GITHUB_PATH"

GH_AUTHENTICATED=$(gh auth status >/dev/null 2>&1; echo $?)

if [ $GH_AUTHENTICATED -eq 0 ]; then
echo "is authenticated"
gh release download "$TAG" --repo "$REPO" --dir "$DOWNLOAD_DIR"
else
echo "not authenticated"
URLS=$(curl -s "https://api.github.com/repos/$REPO/releases/tags/$TAG" \
| jq -r '.assets[] | .browser_download_url')
echo "$URLS" | while read -r url; do
FILENAME=$(basename "$url")
curl -sS -L "$url" -o "$DOWNLOAD_DIR/$FILENAME"
done
fi

chmod +x "$DOWNLOAD_DIR/"*
ls -al "$DOWNLOAD_DIR"