diff --git a/README.md b/README.md index c9d42c23..06062cf0 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,30 @@ docker run --rm -it --env GITHUB_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. +Providing the GH_TOKEN environment variable is recommended to avoid rate limiting by the GitHub API. + +```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. diff --git a/action.yml b/action.yml new file mode 100644 index 00000000..d375d2ef --- /dev/null +++ b/action.yml @@ -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 }}" + 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"