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

Add outputs for the archive and checksum files #77

Merged
merged 8 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ jobs:
if: matrix.target != '' && matrix.build_tool == 'cargo'
- run: cargo new --bin test-crate
- uses: ./
id: upload-rust-binary-action
with:
dry-run: true
bin: test-crate
Expand All @@ -85,3 +86,25 @@ jobs:
zip: all
manifest-path: test-crate/Cargo.toml
codesign: '-'
- name: Check action outputs
run: |
echo "outputs.archive should not be empty"
test -n "${{ steps.upload-rust-binary-action.outputs.archive }}"

echo "outputs.zip should be a file"
test -f "${{ steps.upload-rust-binary-action.outputs.zip }}"

echo "outputs.tar should be a file"
test -f "${{ steps.upload-rust-binary-action.outputs.tar }}"

echo "outputs.sha256 should be a file"
test -f "${{ steps.upload-rust-binary-action.outputs.sha256 }}"

echo "outputs.sha512 should be a file"
test -f "${{ steps.upload-rust-binary-action.outputs.sha512 }}"

echo "outputs.sha1 should be a file"
test -f "${{ steps.upload-rust-binary-action.outputs.sha1 }}"

echo "outputs.md5 should be a file"
test -f "${{ steps.upload-rust-binary-action.outputs.md5 }}"
26 changes: 25 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,37 @@ inputs:
description: Sign build products using `codesign` on macOS
required: false

outputs:
archive:
description: 'Archive base name'
value: ${{ steps.upload-rust-binary-action.outputs.archive }}
zip:
description: 'ZIP archive file name'
value: ${{ steps.upload-rust-binary-action.outputs.zip }}
tar:
description: 'Tar archive file name'
value: ${{ steps.upload-rust-binary-action.outputs.tar }}
sha256:
description: 'SHA256 checksum file name'
value: ${{ steps.upload-rust-binary-action.outputs.sha256 }}
sha512:
description: 'SHA512 checksum file name'
value: ${{ steps.upload-rust-binary-action.outputs.sha512 }}
sha1:
description: 'SHA1 checksum file name'
value: ${{ steps.upload-rust-binary-action.outputs.sha1 }}
md5:
description: 'MD5 checksum file name'
value: ${{ steps.upload-rust-binary-action.outputs.md5 }}

# Note:
# - inputs.* should be manually mapped to INPUT_* due to https://github.com/actions/runner/issues/665
# - Use GITHUB_*/RUNNER_* instead of github.*/runner.* due to https://github.com/actions/runner/issues/2185
runs:
using: composite
steps:
- run: bash --noprofile --norc "${GITHUB_ACTION_PATH:?}/main.sh"
- id: upload-rust-binary-action
run: bash --noprofile --norc "${GITHUB_ACTION_PATH:?}/main.sh"
shell: bash
env:
INPUT_BIN: ${{ inputs.bin }}
Expand Down
47 changes: 47 additions & 0 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ archive="${archive/\$bin/${bin_names[0]}}"
archive="${archive/\$target/${target}}"
archive="${archive/\$tag/${tag}}"

if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
echo "archive=${archive}" >>"${GITHUB_OUTPUT}"
else
warn "GITHUB_OUTPUT is not set; skip setting the 'archive' output"
echo "archive: ${archive}"
fi

input_profile=${INPUT_PROFILE:-release}
case "${input_profile}" in
release) build_options=("--release") ;;
Expand Down Expand Up @@ -384,10 +391,26 @@ if [[ "${INPUT_TAR/all/${platform}}" == "${platform}" ]] || [[ "${INPUT_ZIP/all/
# /${archive}/${includes}
if [[ "${INPUT_TAR/all/${platform}}" == "${platform}" ]]; then
assets+=("${archive}.tar.gz")

if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
echo "tar=${archive}.tar.gz" >>"${GITHUB_OUTPUT}"
else
warn "GITHUB_OUTPUT is not set; skip setting the 'tar' output"
echo "tar: ${checksum}"
fi

x "${tar}" acf "${cwd}/${archive}.tar.gz" "${archive}"
fi
if [[ "${INPUT_ZIP/all/${platform}}" == "${platform}" ]]; then
assets+=("${archive}.zip")

if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
echo "zip=${archive}.zip" >>"${GITHUB_OUTPUT}"
else
warn "GITHUB_OUTPUT is not set; skip setting the 'zip' output"
echo "zip: ${checksum}"
fi

if [[ "${platform}" == "unix" ]]; then
x zip -r "${cwd}/${archive}.zip" "${archive}"
else
Expand All @@ -402,10 +425,26 @@ if [[ "${INPUT_TAR/all/${platform}}" == "${platform}" ]] || [[ "${INPUT_ZIP/all/
pushd "${archive}" >/dev/null
if [[ "${INPUT_TAR/all/${platform}}" == "${platform}" ]]; then
assets+=("${archive}.tar.gz")

if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
echo "tar=${archive}.tar.gz" >>"${GITHUB_OUTPUT}"
else
warn "GITHUB_OUTPUT is not set; skip setting the 'tar' output"
echo "tar: ${checksum}"
fi

x "${tar}" acf "${cwd}/${archive}.tar.gz" "${filenames[@]}"
fi
if [[ "${INPUT_ZIP/all/${platform}}" == "${platform}" ]]; then
assets+=("${archive}.zip")

if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
echo "zip=${archive}.zip" >>"${GITHUB_OUTPUT}"
else
warn "GITHUB_OUTPUT is not set; skip setting the 'zip' output"
echo "zip: ${checksum}"
fi

if [[ "${platform}" == "unix" ]]; then
x zip -r "${cwd}/${archive}.zip" "${filenames[@]}"
else
Expand Down Expand Up @@ -446,6 +485,14 @@ for checksum in ${checksums[@]+"${checksums[@]}"}; do
esac
fi
x cat "${archive}.${checksum}"

if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
echo "${checksum}=${archive}.${checksum}" >>"${GITHUB_OUTPUT}"
else
warn "GITHUB_OUTPUT is not set; skip setting the 'checksum' output"
echo "checksum: ${checksum}"
fi

final_assets+=("${archive}.${checksum}")
done

Expand Down
Loading