-
Notifications
You must be signed in to change notification settings - Fork 11
Fully support sha pinning + remove docker from runtime. #143
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
Changes from all commits
448bec3
ba82e53
7c781b8
4e17f45
b30e0ca
bd23060
e9d1bd3
2cc6c15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,88 @@ inputs: | |
| outputs: | ||
| data: | ||
| description: 'JSON string containing all the codeowners data (success, message, file-owners, file-optional, still-required)' | ||
| value: ${{ steps.run.outputs.data }} | ||
|
|
||
| runs: | ||
| using: 'docker' | ||
| image: 'docker://ghcr.io/multimediallc/codeowners-plus:latest' | ||
| using: 'composite' | ||
| steps: | ||
| - name: 'Resolve codeowners-plus binary' | ||
| id: resolve | ||
| shell: bash | ||
| env: | ||
| # The release tag this commit belongs to. Non-empty only in release | ||
| # commits: set by scripts/prepare-release.sh and cleared by | ||
| # scripts/post-release.sh. When set, the action downloads that | ||
| # release's prebuilt binary; when empty (any non-release ref) it | ||
| # builds from the checked-out source. | ||
| RELEASE_VERSION: '' | ||
| run: | | ||
| set -euo pipefail | ||
| { | ||
| echo "release-version=${RELEASE_VERSION}" | ||
| echo "bin=${RUNNER_TEMP:-/tmp}/codeowners-plus-action/codeowners-plus" | ||
| } >>"$GITHUB_OUTPUT" | ||
|
|
||
| # RELEASE_VERSION not set -> not a release: build from source (cached). | ||
| - name: 'Restore cached built binary' | ||
| id: buildcache | ||
| if: steps.resolve.outputs.release-version == '' | ||
| uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 | ||
| with: | ||
| path: ${{ steps.resolve.outputs.bin }} | ||
| key: codeowners-plus-build-${{ github.action_ref || github.sha }}-${{ runner.os }}-${{ runner.arch }} | ||
|
|
||
| - name: 'Set up Go' | ||
| if: steps.resolve.outputs.release-version == '' && steps.buildcache.outputs.cache-hit != 'true' | ||
| uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6 | ||
| with: | ||
| go-version-file: ${{ github.action_path }}/go.mod | ||
| cache-dependency-path: ${{ github.action_path }}/go.sum | ||
|
|
||
| - name: 'Build codeowners-plus from source' | ||
| if: steps.resolve.outputs.release-version == '' && steps.buildcache.outputs.cache-hit != 'true' | ||
| shell: bash | ||
| env: | ||
| ACTION_PATH: ${{ github.action_path }} | ||
| BIN: ${{ steps.resolve.outputs.bin }} | ||
| run: | | ||
| set -euo pipefail | ||
| mkdir -p "$(dirname "${BIN}")" | ||
| cd "${ACTION_PATH}" | ||
| CGO_ENABLED=0 \ | ||
| go build -trimpath -buildvcs=false -ldflags="-s -w" -o "${BIN}" . | ||
|
|
||
| # RELEASE_VERSION set -> a release: download + verify the prebuilt binary (cached). | ||
| - name: 'Restore cached release binary' | ||
| id: bincache | ||
| if: steps.resolve.outputs.release-version != '' | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think caching after having built from source is the most impactful time to cache. Otherwise non-release shas need to build everytime.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added caching back to the builds - that was an oversight |
||
| uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 | ||
| with: | ||
| path: ${{ steps.resolve.outputs.bin }} | ||
| key: codeowners-plus-action-${{ steps.resolve.outputs.release-version }}-${{ runner.os }}-${{ runner.arch }} | ||
|
|
||
|
Comment on lines
+81
to
+89
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need a separate cache action for build vs download, the cached path is the same. |
||
| - name: 'Download codeowners-plus release binary' | ||
| if: steps.resolve.outputs.release-version != '' && steps.bincache.outputs.cache-hit != 'true' | ||
| shell: bash | ||
| env: | ||
| REPO: ${{ github.action_repository }} | ||
| ACTION_PATH: ${{ github.action_path }} | ||
| TAG: ${{ steps.resolve.outputs.release-version }} | ||
| BIN: ${{ steps.resolve.outputs.bin }} | ||
| run: '"${ACTION_PATH}/scripts/install-action.sh"' | ||
|
|
||
| - name: 'Run codeowners-plus' | ||
| id: run | ||
| shell: bash | ||
| env: | ||
| # The hyphenated INPUT_GITHUB-TOKEN name is intentional: it mirrors | ||
| # what Docker actions export and is exactly what main.go reads via | ||
| # os.LookupEnv. Bash passes non-identifier env vars through to child | ||
| # processes untouched. | ||
| INPUT_GITHUB-TOKEN: ${{ inputs.github-token }} | ||
| INPUT_PR: ${{ inputs.pr }} | ||
| INPUT_REPOSITORY: ${{ inputs.repository }} | ||
| INPUT_VERBOSE: ${{ inputs.verbose }} | ||
| INPUT_QUIET: ${{ inputs.quiet }} | ||
| BIN: ${{ steps.resolve.outputs.bin }} | ||
| run: '"${BIN}"' | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| #! /usr/bin/env bash | ||
| # Installs the prebuilt codeowners-plus binary for the current platform, | ||
| # verified against the release's checksums.txt. | ||
| # | ||
| # Local use (all env vars optional): | ||
| # scripts/install-action.sh # latest release -> ./codeowners-plus | ||
| # VERSION=v1.9.1 scripts/install-action.sh # a specific release | ||
| # BIN=/usr/local/bin/codeowners-plus scripts/install-action.sh | ||
| # curl -fsSL https://raw.githubusercontent.com/multimediallc/codeowners-plus/main/scripts/install-action.sh | bash | ||
| # | ||
| # Overrides: REPO, VERSION (or TAG), OS, ARCH, BIN. action.yml passes | ||
| # REPO/TAG/BIN; OS and ARCH are detected here so the script is self-contained. | ||
|
|
||
| set -eu | ||
|
|
||
| REPO="${REPO:-multimediallc/codeowners-plus}" | ||
| BIN="${BIN:-./codeowners-plus}" | ||
| TAG="${TAG:-${VERSION:-}}" | ||
|
|
||
| # Detect OS unless overridden. Tokens match goreleaser's {{ .Os }}. | ||
| OS="${OS:-}" | ||
| if [ -z "${OS}" ]; then | ||
| case "$(uname -s)" in | ||
| Linux) OS="linux" ;; | ||
| Darwin) OS="darwin" ;; | ||
| *) | ||
| echo "Error: unsupported OS '$(uname -s)' (supported: linux, darwin)." >&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| fi | ||
|
|
||
| # Detect ARCH unless overridden. Tokens match goreleaser's {{ .Arch }}. | ||
| ARCH="${ARCH:-}" | ||
| if [ -z "${ARCH}" ]; then | ||
| case "$(uname -m)" in | ||
| x86_64 | amd64) ARCH="amd64" ;; | ||
| arm64 | aarch64) ARCH="arm64" ;; | ||
| *) | ||
| echo "Error: unsupported arch '$(uname -m)' (supported: amd64, arm64)." >&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| fi | ||
|
|
||
| # Default to the latest release when no version was requested. | ||
| if [ -z "${TAG}" ]; then | ||
| TAG="$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \ | ||
| | awk -F'"' '/"tag_name":/ {print $4; exit}')" | ||
| if [ -z "${TAG}" ]; then | ||
| echo "Error: could not determine the latest release of ${REPO}." >&2 | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| asset="codeowners-plus-action_${OS}_${ARCH}.tar.gz" | ||
| binname="codeowners-plus-action" | ||
| base="https://github.com/${REPO}/releases/download/${TAG}" | ||
| tmp="$(mktemp -d)" | ||
| trap 'rm -rf "${tmp}"' EXIT | ||
|
|
||
| echo "Downloading ${asset} from ${REPO} release ${TAG}" >&2 | ||
| curl -fsSL --retry 3 -o "${tmp}/${asset}" "${base}/${asset}" | ||
| curl -fsSL --retry 3 -o "${tmp}/checksums.txt" "${base}/checksums.txt" | ||
|
|
||
| echo "Verifying ${asset} against checksums.txt" >&2 | ||
| expected="$(awk -v a="${asset}" '$2 == a {print $1}' "${tmp}/checksums.txt")" | ||
| if [ -z "${expected}" ]; then | ||
| echo "Error: ${asset} not found in checksums.txt" >&2 | ||
| exit 1 | ||
| fi | ||
| # Guard against a malformed digest: '<checker> -c' treats an improperly | ||
| # formatted line as a skipped (passing) entry rather than a failure. | ||
| if ! printf '%s' "${expected}" | grep -Eq '^[0-9a-f]{64}$'; then | ||
| echo "Error: invalid checksum for ${asset} in checksums.txt" >&2 | ||
| exit 1 | ||
| fi | ||
| # sha256sum is GNU coreutils (Linux); macOS only ships shasum. | ||
| if command -v sha256sum >/dev/null 2>&1; then | ||
| verify=(sha256sum -c -) | ||
| else | ||
| verify=(shasum -a 256 -c -) | ||
| fi | ||
| if ! echo "${expected} ${tmp}/${asset}" | "${verify[@]}"; then | ||
| echo "Error: downloaded ${asset} does not match its release checksum" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Extracting ${binname} from ${asset}" >&2 | ||
| tar -xzf "${tmp}/${asset}" -C "${tmp}" "${binname}" | ||
|
|
||
| mkdir -p "$(dirname "${BIN}")" | ||
| mv "${tmp}/${binname}" "${BIN}" | ||
| chmod +x "${BIN}" | ||
| echo "Installed codeowners-plus ${TAG} to ${BIN}" >&2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want to try to restore the cache regardless of if built from source or pulled from github.