From 0a6b5bf893afc8eb08dff1f348dddafe3a25678b Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Thu, 30 Dec 2021 17:33:20 +0900 Subject: [PATCH] Initial implementation --- .editorconfig | 22 +++++ .gitattributes | 1 + .github/workflows/ci.yml | 62 ++++++++++++ .github/workflows/release.yml | 30 ++++++ .gitignore | 8 ++ CHANGELOG.md | 18 ++++ LICENSE-APACHE | 177 ++++++++++++++++++++++++++++++++++ LICENSE-MIT | 23 +++++ README.md | 104 ++++++++++++++++++++ action.yml | 12 +++ main.js | 16 +++ main.sh | 139 ++++++++++++++++++++++++++ tools/publish.sh | 116 ++++++++++++++++++++++ tools/tidy.sh | 64 ++++++++++++ 14 files changed, 792 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 LICENSE-APACHE create mode 100644 LICENSE-MIT create mode 100644 README.md create mode 100644 action.yml create mode 100644 main.js create mode 100755 main.sh create mode 100755 tools/publish.sh create mode 100755 tools/tidy.sh diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..73f719ac3 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,22 @@ +# EditorConfig configuration +# https://editorconfig.org + +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{json,md,yml}] +indent_size = 2 + +[*.{js,yml}] +quote_type = single + +[*.sh] +binary_next_line = true +switch_case_indent = true diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..6313b56c5 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..6fc199e84 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,62 @@ +name: CI + +permissions: + contents: read + +on: + pull_request: + push: + branches: + - main + - dev + schedule: + - cron: '0 0 * * *' + workflow_dispatch: + +defaults: + run: + shell: bash + +jobs: + test: + strategy: + fail-fast: false + matrix: + os: + - ubuntu-18.04 + tool: + - cargo-hack,cargo-llvm-cov,cargo-minimal-versions,parse-changelog,cross,shellcheck,shfmt + - cargo-hack@0.5.9,cargo-llvm-cov@0.1.13,cargo-minimal-versions@0.1.0,parse-changelog@0.4.5,cross@0.2.1,shellcheck@0.8.0,shfmt@3.4.2 + include: + - os: macos-10.15 + tool: cargo-hack@0.5.9,cargo-llvm-cov@0.1.13,cargo-minimal-versions@0.1.0,parse-changelog@0.4.5,cross@0.2.1,shellcheck@0.8.0,shfmt@3.4.2 + - os: windows-2019 + tool: cargo-hack,cargo-llvm-cov,cargo-minimal-versions,parse-changelog + - os: windows-2019 + tool: cargo-hack@0.5.9,cargo-llvm-cov@0.1.13,cargo-minimal-versions@0.1.0,parse-changelog@0.4.5,cross@0.2.1 + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + with: + persist-credentials: false + - uses: ./ + with: + tool: ${{ matrix.tool }} + + tidy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + persist-credentials: false + - uses: taiki-e/github-actions/install@main + with: + tool: prettier,shellcheck,shfmt + - run: shfmt -d $(git ls-files '*.sh') + if: always() + - run: npx prettier -c $(git ls-files '*.yml') + if: always() + - run: npx prettier -c $(git ls-files '*.js') + if: always() + - run: shellcheck $(git ls-files '*.sh') + if: always() diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..66713273c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,30 @@ +name: Release + +permissions: + # TODO: once `releases: write` is supported, use it instead. + contents: write + +on: + push: + tags: + - v[0-9]+.[0-9]+.* + +defaults: + run: + shell: bash + +jobs: + create-release: + if: github.repository_owner == 'taiki-e' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + persist-credentials: false + - uses: taiki-e/create-gh-release-action@v1 + with: + changelog: CHANGELOG.md + title: $version + branch: 'main|v[0-9]+' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..9f491df9c --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +node_modules +package-lock.json +package.json +tmp + +# For platform and editor specific settings, it is recommended to add to +# a global .gitignore file. +# Refs: https://docs.github.com/en/github/using-git/ignoring-files#configuring-ignored-files-for-all-repositories-on-your-computer diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..ad3ad1596 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,18 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +This project adheres to [Semantic Versioning](https://semver.org). + + + +## [Unreleased] + +## [1.0.0] - 2021-12-30 + +Initial release + +[Unreleased]: https://github.com/taiki-e/install-action/compare/v1.0.0...HEAD +[1.0.0]: https://github.com/taiki-e/install-action/releases/tag/v1.0.0 diff --git a/LICENSE-APACHE b/LICENSE-APACHE new file mode 100644 index 000000000..f433b1a53 --- /dev/null +++ b/LICENSE-APACHE @@ -0,0 +1,177 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 000000000..31aa79387 --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,23 @@ +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 000000000..4467d7d9a --- /dev/null +++ b/README.md @@ -0,0 +1,104 @@ +# install-action + +[![build status](https://img.shields.io/github/workflow/status/taiki-e/install-action/CI/main?style=flat-square&logo=github)](https://github.com/taiki-e/install-action/actions) + +GitHub Action for installing development tools (mainly from GitHub Releases). + +- [Usage](#usage) + - [Inputs](#inputs) + - [Example workflow](#example-workflow) +- [Supported tools](#supported-tools) +- [Security](#security) +- [Related Projects](#related-projects) +- [License](#license) + +## Usage + +### Inputs + +| Name | Required | Description | Type | Default | +| ---- |:--------:| ----------- | ---- | ------- | +| tool | **true** | Tools to install (comma-separated list) | String | | + +### Example workflow + +```yaml +- uses: taiki-e/install-action@v1 + with: + tool: cargo-hack +``` + +You can use the shorthand (if you do not need to pin the versions of this action and the installed tool): + +```yaml +- uses: taiki-e/install-action@cargo-hack +``` + +To install a specific version, use `@version` syntax: + +```yaml +- uses: taiki-e/install-action@v1 + with: + tool: cargo-hack@0.5.9 +``` + +To install multiple tools: + +```yaml +- uses: taiki-e/install-action@v1 + with: + tool: cargo-hack,cargo-minimal-versions +``` + +Or: + +```yaml +- uses: taiki-e/install-action@cargo-hack +- uses: taiki-e/install-action@cargo-minimal-versions +``` + +## Supported tools + + + +| Name | Where binaries will be installed | Where will it be installed from | Supported platform | License | +| ---- | -------------------------------- | ------------------------------- | ------------------ | ------- | +| [**cargo-hack**](https://github.com/taiki-e/cargo-hack) | `~/.cargo/bin` | [GitHub Releases](https://github.com/taiki-e/cargo-hack/releases) | Linux, macOS, Windows | [Apache-2.0](https://github.com/taiki-e/cargo-hack/blob/HEAD/LICENSE-APACHE) OR [MIT](https://github.com/taiki-e/cargo-hack/blob/HEAD/LICENSE-MIT) | +| [**cargo-llvm-cov**](https://github.com/taiki-e/cargo-llvm-cov) | `~/.cargo/bin` | [GitHub Releases](https://github.com/taiki-e/cargo-llvm-cov/releases) | Linux, macOS, Windows | [Apache-2.0](https://github.com/taiki-e/cargo-llvm-cov/blob/HEAD/LICENSE-APACHE) OR [MIT](https://github.com/taiki-e/cargo-llvm-cov/blob/HEAD/LICENSE-MIT) | +| [**cargo-minimal-versions**](https://github.com/taiki-e/cargo-minimal-versions) | `~/.cargo/bin` | [GitHub Releases](https://github.com/taiki-e/cargo-minimal-versions/releases) | Linux, macOS, Windows | [Apache-2.0](https://github.com/taiki-e/cargo-minimal-versions/blob/HEAD/LICENSE-APACHE) OR [MIT](https://github.com/taiki-e/cargo-minimal-versions/blob/HEAD/LICENSE-MIT) | +| [**parse-changelog**](https://github.com/taiki-e/parse-changelog) | `~/.cargo/bin` | [GitHub Releases](https://github.com/taiki-e/parse-changelog/releases) | Linux, macOS, Windows | [Apache-2.0](https://github.com/taiki-e/parse-changelog/blob/HEAD/LICENSE-APACHE) OR [MIT](https://github.com/taiki-e/parse-changelog/blob/HEAD/LICENSE-MIT) | +| [**cross**](https://github.com/rust-embedded/cross) | `~/.cargo/bin` | [GitHub Releases](https://github.com/rust-embedded/cross/releases) | Linux, macOS, Windows | [Apache-2.0](https://github.com/rust-embedded/cross/blob/HEAD/LICENSE-APACHE) OR [MIT](https://github.com/rust-embedded/cross/blob/HEAD/LICENSE-MIT) | +| [**shellcheck**](https://www.shellcheck.net) | `/usr/local/bin` | [GitHub Releases](https://github.com/koalaman/shellcheck/releases) | Linux, macOS | [GPL-3.0-or-later](https://github.com/koalaman/shellcheck/blob/HEAD/LICENSE) | +| [**shfmt**](https://github.com/mvdan/sh) | `/usr/local/bin` | [GitHub Releases](https://github.com/mvdan/sh/releases) | Linux, macOS | [BSD-3-Clause](https://github.com/mvdan/sh/blob/HEAD/LICENSE) | + + + +## Security + +When installing the tool from GitHub Releases, this action will download the tool or its installer from GitHub Releases using HTTPS with tlsv1.2+. This is basically considered to be the same level of security as [the recommended installation of rustup](https://www.rust-lang.org/tools/install). + +If you want a higher level of security, consider working on [#1](https://github.com/taiki-e/install-action/issues/1). + +## Related Projects + +- [create-gh-release-action]: GitHub Action for creating GitHub Releases based on changelog. +- [upload-rust-binary-action]: GitHub Action for building and uploading Rust binary to GitHub Releases. + +[create-gh-release-action]: https://github.com/taiki-e/create-gh-release-action +[upload-rust-binary-action]: https://github.com/taiki-e/upload-rust-binary-action + +## License + +Licensed under either of [Apache License, Version 2.0](LICENSE-APACHE) or +[MIT license](LICENSE-MIT) at your option. + +Each of the tools installed by this action has a different license. See the [Supported tools](#supported-tools) section for more information. + +Unless you explicitly state otherwise, any contribution intentionally submitted +for inclusion in the work by you, as defined in the Apache-2.0 license, shall +be dual licensed as above, without any additional terms or conditions. diff --git a/action.yml b/action.yml new file mode 100644 index 000000000..0eac1f138 --- /dev/null +++ b/action.yml @@ -0,0 +1,12 @@ +name: Install development tools +description: GitHub Action for installing development tools + +inputs: + tool: + description: Tools to install (comma-separated list) + required: true + # default: #publish:tool + +runs: + using: node16 + main: main.js diff --git a/main.js b/main.js new file mode 100644 index 000000000..3cb8b9008 --- /dev/null +++ b/main.js @@ -0,0 +1,16 @@ +const { execFileSync } = require('child_process'); + +function main() { + try { + execFileSync( + 'bash', + ['--noprofile', '--norc', `${__dirname}/main.sh`], + { stdio: 'inherit' } + ); + } catch (e) { + console.log(`::error::${e.message}`); + process.exit(1); + } +} + +main(); diff --git a/main.sh b/main.sh new file mode 100755 index 000000000..6eaf054c4 --- /dev/null +++ b/main.sh @@ -0,0 +1,139 @@ +#!/bin/bash +set -euo pipefail +IFS=$'\n\t' + +x() { + local cmd="$1" + shift + ( + set -x + "${cmd}" "$@" + ) +} +retry() { + for i in {1..5}; do + if "$@"; then + return 0 + else + sleep "${i}" + fi + done + "$@" +} +bail() { + echo "::error::$*" + exit 1 +} +warn() { + echo "::warning::$*" +} +info() { + echo >&2 "info: $*" +} + +if [[ $# -gt 0 ]]; then + bail "invalid argument '$1'" +fi + +export DEBIAN_FRONTEND=noninteractive + +# Inputs +tool="${INPUT_TOOL:-}" + +tools=() +if [[ -n "${tool}" ]]; then + while read -rd,; do tools+=("${REPLY}"); done <<<"${tool}," +fi + +for tool in "${tools[@]}"; do + if [[ "${tool}" == *"@"* ]]; then + version="${tool#*@}" + else + version="latest" + fi + tool="${tool%@*}" + info "installing ${tool}@${version}" + case "${tool}" in + # https://github.com/taiki-e/cargo-hack/releases + # https://github.com/taiki-e/cargo-llvm-cov/releases + # https://github.com/taiki-e/cargo-minimal-versions/releases + # https://github.com/taiki-e/parse-changelog/releases + cargo-hack | cargo-llvm-cov | cargo-minimal-versions | parse-changelog) + repo="taiki-e/${tool}" + case "${OSTYPE}" in + linux*) target="x86_64-unknown-linux-musl" ;; + darwin*) target="x86_64-apple-darwin" ;; + cygwin* | msys*) target="x86_64-pc-windows-msvc" ;; + *) bail "unsupported OSTYPE '${OSTYPE}' for ${tool}" ;; + esac + case "${version}" in + latest) url="https://github.com/${repo}/releases/latest/download/${tool}-${target}.tar.gz" ;; + *) url="https://github.com/${repo}/releases/download/v${version}/${tool}-${target}.tar.gz" ;; + esac + retry curl --proto '=https' --tlsv1.2 -fsSL --retry 10 --retry-connrefused "${url}" \ + | tar xzf - -C ~/.cargo/bin + ;; + # https://github.com/rust-embedded/cross/releases + cross) + repo="rust-embedded/cross" + case "${OSTYPE}" in + linux*) target="x86_64-unknown-linux-musl" ;; + darwin*) target="x86_64-apple-darwin" ;; + cygwin* | msys*) target="x86_64-pc-windows-msvc" ;; + *) bail "unsupported OSTYPE '${OSTYPE}' for ${tool}" ;; + esac + case "${version}" in + latest) tag=$(retry curl --proto '=https' --tlsv1.2 -fsSL --retry 10 --retry-connrefused https://api.github.com/repos/${repo}/releases/latest | jq -r '.tag_name') ;; + *) tag="v${version}" ;; + esac + url="https://github.com/${repo}/releases/download/${tag}/cross-${tag}-${target}.tar.gz" + retry curl --proto '=https' --tlsv1.2 -fsSL --retry 10 --retry-connrefused "${url}" \ + | tar xzf - -C ~/.cargo/bin + ;; + # https://github.com/koalaman/shellcheck/releases + shellcheck) + repo="koalaman/shellcheck" + case "${OSTYPE}" in + linux*) + if type -P shellcheck &>/dev/null; then + sudo apt-get -qq -o Dpkg::Use-Pty=0 remove -y shellcheck + fi + target="linux" + ;; + darwin*) target="darwin" ;; + cygwin* | msys*) bail "${tool} for windows is not supported yet by this action" ;; + *) bail "unsupported OSTYPE '${OSTYPE}' for ${tool}" ;; + esac + case "${version}" in + latest) tag="$(retry curl --proto '=https' --tlsv1.2 -fsSL --retry 10 --retry-connrefused https://api.github.com/repos/${repo}/releases/latest | jq -r '.tag_name')" ;; + *) tag="v${version}" ;; + esac + retry curl --proto '=https' --tlsv1.2 -fsSL --retry 10 --retry-connrefused "https://github.com/${repo}/releases/download/${tag}/shellcheck-${tag}.${target}.x86_64.tar.xz" \ + | tar xJf - --strip-components 1 -C /usr/local/bin "shellcheck-${tag}/shellcheck" + ;; + # https://github.com/mvdan/sh/releases + shfmt) + repo="mvdan/sh" + case "${OSTYPE}" in + linux*) target="linux_amd64" ;; + darwin*) target="darwin_amd64" ;; + cygwin* | msys*) bail "${tool} for windows is not supported yet by this action" ;; + *) bail "unsupported OSTYPE '${OSTYPE}' for ${tool}" ;; + esac + case "${version}" in + latest) tag="$(retry curl --proto '=https' --tlsv1.2 -fsSL --retry 10 --retry-connrefused https://api.github.com/repos/${repo}/releases/latest | jq -r '.tag_name')" ;; + *) tag="v${version}" ;; + esac + retry curl --proto '=https' --tlsv1.2 -fsSL --retry 10 --retry-connrefused -o /usr/local/bin/shfmt "https://github.com/${repo}/releases/download/${tag}/shfmt_${tag}_${target}" + chmod +x /usr/local/bin/shfmt + ;; + *) bail "unsupported tool '${tool}'" ;; + esac + + info "${tool} installed at $(type -P "${tool}")" + case "${tool}" in + cargo-*) x cargo "${tool#cargo-}" --version ;; + *) x "${tool}" --version ;; + esac + echo >&2 +done diff --git a/tools/publish.sh b/tools/publish.sh new file mode 100755 index 000000000..0ab676182 --- /dev/null +++ b/tools/publish.sh @@ -0,0 +1,116 @@ +#!/bin/bash +set -euo pipefail +IFS=$'\n\t' + +# Publish a new release. +# +# USAGE: +# ./tools/publish.sh +# +# NOTE: +# - This script requires parse-changelog + +cd "$(cd "$(dirname "$0")" && pwd)"/.. + +bail() { + echo >&2 "error: $*" + exit 1 +} +warn() { + echo >&2 "warning: $*" +} +info() { + echo >&2 "info: $*" +} + +tools=( + cargo-hack + cargo-llvm-cov + cargo-minimal-versions + parse-changelog + cross + shellcheck + shfmt +) + +# Parse arguments. +version="${1:?}" +version="${version#v}" +tag="v${version}" +if [[ ! "${version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z\.-]+)?(\+[0-9A-Za-z\.-]+)?$ ]]; then + bail "invalid version format: '${version}'" +fi +if [[ "${2:-}" == "--dry-run" ]]; then + dry_run="--dry-run" + shift +fi +if [[ $# -gt 1 ]]; then + bail "invalid argument: '$2'" +fi + +if [[ -z "${dry_run:-}" ]]; then + git diff --exit-code + git diff --exit-code --staged +fi + +# Make sure that a valid release note for this version exists. +# https://github.com/taiki-e/parse-changelog +echo "============== CHANGELOG ==============" +parse-changelog CHANGELOG.md "${version}" +echo "=======================================" + +# Make sure the same release has not been created in the past. +if gh release view "${tag}" &>/dev/null; then + bail "tag '${tag}' has already been created and pushed" +fi + +# Exit if dry run. +if [[ -n "${dry_run:-}" ]]; then + warn "skip creating a new tag '${tag}' due to dry run" + exit 0 +fi + +info "creating and pushing a new tag '${tag}'" + +( + set -x + + git push origin main + git tag "${tag}" + git push origin --tags + sleep 10 + + version_tag=v1 + git checkout -b "${version_tag}" + git push origin -f refs/heads/"${version_tag}" + if git --no-pager tag | grep -E "^${version_tag}$" &>/dev/null; then + git tag -d "${version_tag}" + git push --delete origin refs/tags/"${version_tag}" + fi + git tag "${version_tag}" + git checkout main + git branch -d "${version_tag}" +) + +for tool in "${tools[@]}"; do + ( + set -x + git checkout -b "${tool}" + sed -i -e "s/required: true/required: false/g" action.yml + sed -i -e "s/# default: #publish:tool/default: ${tool}/g" action.yml + git add action.yml + git commit -m "${tool}" + git push origin -f refs/heads/"${tool}" + if git --no-pager tag | grep -E "^${tool}$" &>/dev/null; then + git tag -d "${tool}" + git push --delete origin refs/tags/"${tool}" + fi + git tag "${tool}" + git checkout main + git branch -D "${tool}" + ) +done + +set -x + +git push origin --tags diff --git a/tools/tidy.sh b/tools/tidy.sh new file mode 100755 index 000000000..abe563d2f --- /dev/null +++ b/tools/tidy.sh @@ -0,0 +1,64 @@ +#!/bin/bash +# shellcheck disable=SC2046 +set -euo pipefail +IFS=$'\n\t' + +# USAGE: +# ./tools/tidy.sh +# +# NOTE: This script requires the following tools: +# - shfmt +# - prettier +# - shellcheck + +cd "$(cd "$(dirname "$0")" && pwd)"/.. + +x() { + local cmd="$1" + shift + if [[ -n "${verbose:-}" ]]; then + ( + set -x + "${cmd}" "$@" + ) + else + "${cmd}" "$@" + fi +} +warn() { + echo >&2 "warning: $*" +} + +if [[ "${1:-}" == "-v" ]]; then + shift + verbose=1 +fi +if [[ $# -gt 0 ]]; then + cat </dev/null && type -P "$(npm bin)/prettier" &>/dev/null; then + prettier="$(npm bin)/prettier" +fi + +if type -P shfmt &>/dev/null; then + x shfmt -l -w $(git ls-files '*.sh') +else + warn "'shfmt' is not installed" +fi +if type -P "${prettier}" &>/dev/null; then + x "${prettier}" -l -w $(git ls-files '*.yml') + x "${prettier}" -l -w $(git ls-files '*.js') +else + warn "'prettier' is not installed" +fi +if type -P shellcheck &>/dev/null; then + x shellcheck $(git ls-files '*.sh') +else + warn "'shellcheck' is not installed" +fi