engineerd / configurator

Cross-platform GitHub Action to download, extract, and add to path statically compiled tools
https://radu-matei.com/blog/github-action-cross-plat-configure-tools/
MIT License
27 stars 13 forks source link
github github-actions

@engineerd/configurator

Cross-platform GitHub Action for downloading statically compiled tools (or archives) and adding them to the path. This has been tested on ubuntu-latest, windows-latest, and macos-latest.

This action can be used in two modes:

Directly downloading tools based on URL

Inputs:

Examples - a cross-platform action that downloads, extracts, and adds Helm v3.3.0 to the path:

jobs:
  configurator:
    runs-on: ${{ matrix.config.os }}
    strategy:
      matrix:
        config:
          - {
              os: "ubuntu-latest",
              url: "https://get.helm.sh/helm-v3.3.0-linux-amd64.tar.gz",
              name: "h3",
              pathInArchive: "linux-amd64/helm",
            }
          - {
              os: "windows-latest",
              url: "https://get.helm.sh/helm-v3.3.0-windows-amd64.zip",
              name: "h3.exe",
              pathInArchive: "windows-amd64/helm.exe",
            }
    steps:
      - uses: engineerd/configurator@v0.0.9
        with:
          name: ${{ matrix.config.name }}
          url: ${{ matrix.config.url }}
          pathInArchive: ${{ matrix.config.pathInArchive }}
      - name: Testing
        run: |
          h3 --help

Selecting versions from GitHub Releases

Inputs:

Example - a cross-platform action that selects the latest Helm version that satisfies the ^3.1.2 release constraint - meaning it selects any minor and patch update, or, in other words, the latest v3.x.x version:

jobs:
  configurator:
    runs-on: ${{ matrix.config.os }}
    strategy:
      matrix:
        config:
          - {
              os: "ubuntu-latest",
              urlTemplate: "https://get.helm.sh/helm-{{version}}-linux-amd64.tar.gz",
              name: "h3",
              pathInArchive: "linux-amd64/helm",
            }
          - {
              os: "windows-latest",
              urlTemplate: "https://get.helm.sh/helm-{{version}}-windows-amd64.zip",
              name: "h3.exe",
              pathInArchive: "windows-amd64/helm.exe",
            }
    steps:
      - uses: engineerd/configurator@v0.0.9
        with:
          name: ${{ matrix.config.name }}
          pathInArchive: ${{ matrix.config.pathInArchive }}
          fromGitHubReleases: "true"
          repo: "helm/helm"
          version: "^v3.1.2"
          urlTemplate: ${{ matrix.config.urlTemplate }}
          token: ${{ secrets.GITHUB_TOKEN }}

      - name: Testing
        run: |
          h3 --help

Example - an action that selects the latest non-pre-release (as marked in the GitHub release) of Kind:

jobs:
  kind:
    runs-on: ubuntu-latest
    steps:
      - uses: engineerd/configurator@v0.0.9
        with:
          name: "kind"
          fromGitHubReleases: "true"
          repo: "kubernetes-sigs/kind"
          urlTemplate: "https://github.com/kubernetes-sigs/kind/releases/download/{{version}}/kind-linux-amd64"
          version: "latest"
          token: ${{ secrets.GITHUB_TOKEN }}

      - name: Testing
        run: |
          kind --help

Other examples

name: "Test plain file"
on: [pull_request, push]

jobs:
  kind:
    runs-on: ubuntu-latest
    steps:
      - uses: engineerd/configurator@v0.0.9
        with:
          name: "kind"
          url: "https://github.com/kubernetes-sigs/kind/releases/download/v0.8.1/kind-linux-amd64"
      - name: Testing
        run: |
          kind --help
name: "Test .tar.gz"
on: [pull_request, push]

jobs:
  kind:
    runs-on: ubuntu-latest
    steps:
      - uses: engineerd/configurator@v0.0.9
        with:
          name: "h3"
          url: "https://get.helm.sh/helm-v3.3.0-linux-amd64.tar.gz"
          pathInArchive: "linux-amd64/helm"
      - name: Testing
        run: |
          h3 --help
name: "Test .zip"
on: [pull_request, push]

jobs:
  kind:
    runs-on: windows-latest
    steps:
      - uses: engineerd/configurator@v0.0.9
        with:
          name: "h3.exe"
          url: "https://get.helm.sh/helm-v3.3.0-windows-amd64.zip"
          pathInArchive: "windows-amd64/helm.exe"
      - name: Testing
        run: |
          h3 --help

Note: usually, Windows-specific tooling uses .zip archives - and the tar utility on Windows doesn't seem to handle .tar.gz files properly. Note: for Linux, chmod +x is called on the target file before moving it to the path, ensuring it is executable. On Windows this is skipped.