Skip to content

Commit

Permalink
Add outputs for the archive and checksum files (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
matiaskorhonen authored Jun 2, 2024
1 parent 64a054b commit 0ce34a6
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
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

0 comments on commit 0ce34a6

Please sign in to comment.