Skip to content

Commit

Permalink
Add dry_run input option
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Oct 9, 2023
1 parent f0e6e08 commit e0b4b6f
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 4 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,49 @@ concurrency:
jobs:
tidy:
uses: taiki-e/github-actions/.github/workflows/tidy.yml@main

test:
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
build_tool: cargo
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu.2.17
build_tool: cargo-zigbuild
- os: macos-latest
- os: macos-latest
target: aarch64-apple-darwin
- os: macos-latest
target: universal-apple-darwin
- os: windows-latest
- os: windows-latest
target: aarch64-pc-windows-msvc
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install Rust
run: rustup toolchain add nightly --no-self-update && rustup default nightly
- uses: taiki-e/setup-cross-toolchain-action@v1
with:
target: ${{ matrix.target }}
if: matrix.target != '' && matrix.build_tool == 'cargo'
- run: cargo new --bin test-crate
- uses: ./
with:
dry_run: true
bin: test-crate
target: ${{ matrix.target }}
build_tool: ${{ matrix.build_tool }}
checksum: sha256,sha512,sha1,md5
tar: all
zip: all
manifest_path: test-crate/Cargo.toml
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Currently, this action is basically intended to be used in combination with an a
| ref | false | Fully-formed tag ref for this release (see [action.yml](action.yml) for more) | String | |
| manifest_path | false | Path to Cargo.toml | String | `Cargo.toml` |
| profile | false | The cargo profile to build. This defaults to the release profile. | String | `release` |
| dry_run | false | Build and compress binaries, but do not upload them (see [action.yml](action.yml) for more) | Boolean | `false` |

[^1]: Required one of `token` input option or `GITHUB_TOKEN` environment variable.

Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ inputs:
description: The cargo profile to build. This defaults to the release profile.
required: false
default: 'release'
dry_run:
description: >
Build and compress binaries, but do not upload them.
Note that some errors are downgraded to warnings in this mode.
required: false
default: 'false'

# TODO: allow kebab-case input option names?
# Note:
Expand Down Expand Up @@ -95,3 +102,4 @@ runs:
INPUT_TOKEN: ${{ inputs.token }}
INPUT_REF: ${{ inputs.ref }}
INPUT_PROFILE: ${{ inputs.profile }}
INPUT_DRY_RUN: ${{ inputs.dry_run }}
39 changes: 35 additions & 4 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ bail() {
warn() {
echo "::warning::$*"
}
info() {
echo "info: $*"
}

export CARGO_NET_RETRY=10
export RUSTUP_MAX_RETRIES=10
Expand All @@ -36,15 +39,35 @@ if [[ $# -gt 0 ]]; then
bail "invalid argument '$1'"
fi

dry_run="${INPUT_DRY_RUN:-}"
case "${dry_run}" in
true) dry_run="1" ;;
false) dry_run="" ;;
*) bail "'dry_run' input option must be 'true' or 'false': '${dry_run}'" ;;
esac

token="${INPUT_TOKEN:-"${GITHUB_TOKEN:-}"}"
ref="${INPUT_REF:-"${GITHUB_REF:-}"}"

if [[ -z "${token}" ]]; then
bail "neither GITHUB_TOKEN environment variable nor 'token' input option is set"
if [[ -n "${dry_run}" ]]; then
# TODO: The warnings are somewhat noisy if we have a lot of build matrix:
# https://github.com/taiki-e/upload-rust-binary-action/pull/55#discussion_r1349880455
warn "neither GITHUB_TOKEN environment variable nor 'token' input option is set (downgraded error to info because action is running in dry-run mode)"
else
bail "neither GITHUB_TOKEN environment variable nor 'token' input option is set"
fi
fi

if [[ "${ref}" != "refs/tags/"* ]]; then
bail "tag ref should start with 'refs/tags/': '${ref}'; this action only supports events from tag or release by default; see <https://github.com/taiki-e/create-gh-release-action#supported-events> for more"
if [[ -n "${dry_run}" ]]; then
# TODO: The warnings are somewhat noisy if we have a lot of build matrix:
# https://github.com/taiki-e/upload-rust-binary-action/pull/55#discussion_r1349880455
warn "tag ref should start with 'refs/tags/': '${ref}'; this action only supports events from tag or release by default; see <https://github.com/taiki-e/create-gh-release-action#supported-events> for more (downgraded error to info because action is running in dry-run mode)"
ref='refs/tags/dry-run'
else
bail "tag ref should start with 'refs/tags/': '${ref}'; this action only supports events from tag or release by default; see <https://github.com/taiki-e/create-gh-release-action#supported-events> for more"
fi
fi
tag="${ref#refs/tags/}"

Expand Down Expand Up @@ -395,5 +418,13 @@ for checksum in ${checksums[@]+"${checksums[@]}"}; do
final_assets+=("${archive}.${checksum}")
done

# https://cli.github.com/manual/gh_release_upload
GITHUB_TOKEN="${token}" retry gh release upload "${tag}" "${final_assets[@]}" --clobber
if [[ -n "${dry_run}" ]]; then
info "skipped upload because action is running in dry-run mode"
echo "tag: ${tag} ('dry-run' if tag ref is not start with 'refs/tags/')"
IFS=','
echo "assets: ${final_assets[*]}"
IFS=$'\n\t'
else
# https://cli.github.com/manual/gh_release_upload
GITHUB_TOKEN="${token}" retry gh release upload "${tag}" "${final_assets[@]}" --clobber
fi

0 comments on commit e0b4b6f

Please sign in to comment.