diff --git a/.github/workflows/self-test.yml b/.github/workflows/self-test.yml new file mode 100644 index 0000000..9e5c1e3 --- /dev/null +++ b/.github/workflows/self-test.yml @@ -0,0 +1,31 @@ +on: + pull_request: + branches: ['*'] + push: + branches: ['main'] + schedule: + - cron: "18 18 * * 1" + +jobs: + selfcheck: + name: Test Action + strategy: + matrix: + runner: [ubuntu-22.04, ubuntu-24.04, ubuntu-latest] + version: [latest, 9.5.1, 10.0.0] + runs-on: ${{ matrix.runner }} + steps: + # To use this repository's private action, + # you must check out the repository + - name: Checkout + uses: actions/checkout@v4 + - uses: ./ + with: + version: ${{matrix.version}} + lint-with-pre-commit: + runs-on: ubuntu-24.04 + name: Lint with pre-commit + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + - uses: instrumentl/pre-commit-action@v4 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..ea8b936 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,16 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - id: fix-byte-order-marker + - id: check-json + - id: check-merge-conflict +- repo: https://github.com/Mateusz-Grzelinski/actionlint-py + rev: v1.7.4.20 + hooks: + - id: actionlint + additional_dependencies: [ pyflakes>=3.0.1, shellcheck-py>=0.9.0.5 ] diff --git a/README.md b/README.md index c77fc62..3bd7a20 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,9 @@ This is a small GitHub action that runs the Heroku installer to set up the `hero ```yaml - uses: instrumentl/setup-heroku@v1 + with: + # Pass "latest" here to use whatever heroku has made the default; otherwise, you + # can pass a specific version (e.g., '9.5.1') which must exactly match a version + # string in the undocumented heroku-cli manifest + version: 'latest' ``` diff --git a/action.yml b/action.yml index df941c8..01a35e2 100644 --- a/action.yml +++ b/action.yml @@ -1,14 +1,79 @@ name: 'Set up Heroku' description: 'Set up the Heroku CLI' +inputs: + version: + description: "Version to install" + required: true + default: "latest" runs: using: "composite" steps: - - name: "Ensure GPG installed" + - name: "Ensure dependencies are installed" shell: bash - run: "if ! command -v gpg; then apt-get install --no-install-recommends gnupg2 ; fi" + run: | + if ! command -v gpg; then sudo -n apt-get install --no-install-recommends gnupg2 ; fi + if ! command -v curl; then sudo -n apt-get install --no-install-recommends curl ; fi + if ! command -v jq; then sudo -n apt-get install --no-install-recommends jq ; fi + - name: "Determine download url" + id: get_url + shell: bash + env: + version: ${{ inputs.version }} + run: | + set -euo pipefail + + wd="$(mktemp -d)" + on_exit() { + status=$? + [[ -n "$wd" ]] && rm -rf "$wd" + exit $status + } + + trap on_exit EXIT INT TERM + raw_machine="$(uname -m)" + if [[ "$raw_machine" = "aarch64" ]]; then + machine="arm" + elif [[ "$raw_machine" = "x86_64" ]]; then + machine="x64" + else + echo >&2 "Unhandled machine type $raw_machine" + exit 1 + fi + + curl -fqs -o "$wd/versions.json" "https://cli-assets.heroku.com/versions/heroku-linux-${machine}-tar-gz.json" + if [[ "$version" = "latest" ]]; then + url="https://cli-assets.heroku.com/channels/stable/heroku-linux-${machine}.tar.gz" + else + url="$(jq -cr '.["'"${version}"'"]' < "$wd/versions.json")" + fi + if [[ -z "$url" ]] || [[ "$url" = "null" ]]; then + echo >&2 "Could not find download for ${version} for ${machine}" + exit 1 + fi + echo "url=${url}" >> "$GITHUB_OUTPUT" + - name: Cache CLI + id: cache_cli + uses: actions/cache@v4 + with: + path: /tmp/heroku-${{ inputs.version }}.tar.gz + key: ${{ runner.os }}-${{ runner.arch }}-${{ steps.get_url.outputs.url }} + - name: "Download CLI" + shell: bash + if: steps.cache_cli.outputs.cache-hit != 'true' + run: | + curl -o "/tmp/heroku-${{ inputs.version }}.tar.gz" -sq "${{ steps.get_url.outputs.url }}" - name: "Install Heroku CLI" shell: bash - run: "curl -f https://cli-assets.heroku.com/install-ubuntu.sh | sh" + run: | + set -euo pipefail + + sudo -n rm -rf /usr/local/lib/heroku + sudo -n mkdir -p /usr/local/lib/heroku + sudo -n tar -C /usr/local/lib -xpzf "/tmp/heroku-${{ inputs.version }}.tar.gz" + sudo -n rm -f /usr/local/bin/heroku + sudo -n ln -s /usr/local/lib/heroku/bin/heroku /usr/local/bin/heroku + + /usr/local/lib/heroku/bin/node -v || sudo -n rm /usr/local/lib/heroku/bin/node - name: "Test that it runs correctly" run: "heroku version" shell: bash