diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 05460b39..de199cee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 }}" diff --git a/action.yml b/action.yml index bc1823d7..f07698a0 100644 --- a/action.yml +++ b/action.yml @@ -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 }} diff --git a/main.sh b/main.sh index e41d6eed..338361fc 100755 --- a/main.sh +++ b/main.sh @@ -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") ;; @@ -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 @@ -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 @@ -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