From c49d534a27bfc990b361ddb679e7448af46af96c Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sun, 21 Nov 2021 16:55:21 -0800 Subject: [PATCH] Refactor github actions (#1028) --- .cargo/config | 2 - .github/workflows/build.yaml | 175 --------------------------------- .github/workflows/release.yaml | 112 +++++++++++++++++++++ .github/workflows/test.yaml | 61 ++++++++++++ README.adoc | 2 +- bin/package | 43 ++++---- rust-toolchain | 1 - 7 files changed, 194 insertions(+), 202 deletions(-) delete mode 100644 .cargo/config delete mode 100644 .github/workflows/build.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 .github/workflows/test.yaml delete mode 100644 rust-toolchain diff --git a/.cargo/config b/.cargo/config deleted file mode 100644 index 3c32d25..0000000 --- a/.cargo/config +++ /dev/null @@ -1,2 +0,0 @@ -[target.aarch64-unknown-linux-gnu] -linker = "aarch64-linux-gnu-gcc" diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml deleted file mode 100644 index 95962bc..0000000 --- a/.github/workflows/build.yaml +++ /dev/null @@ -1,175 +0,0 @@ -name: Build - -on: - push: - branches: - - master - tags: - - '*' - pull_request: - branches: - - master - -defaults: - run: - shell: bash - -jobs: - all: - name: All - - strategy: - matrix: - target: - - aarch64-unknown-linux-gnu - - x86_64-apple-darwin - - x86_64-pc-windows-msvc - - x86_64-unknown-linux-musl - include: - - target: x86_64-unknown-linux-musl - os: ubuntu-latest - native: true - - target: x86_64-apple-darwin - os: macos-latest - native: true - - target: x86_64-pc-windows-msvc - os: windows-2016 - native: true - - target: aarch64-unknown-linux-gnu - os: ubuntu-latest - native: false - - runs-on: ${{matrix.os}} - - env: - RUSTFLAGS: --deny warnings - - steps: - - uses: actions/checkout@v2 - - - name: Download actionlint - id: actionlint - run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash) - - - name: Check Github Actions Workflow - env: - SHELLCHECK_OPTS: "-e SC2006 -e SC2002 -e SC2050" - run: ${{ steps.actionlint.outputs.executable }} -color - - # An issue with BSD Tar causes sporadic failures on macOS. - # c.f https://github.com/actions/cache/issues/403 - - name: Install GNU Tar - if: ${{ matrix.os == 'macos-latest' }} - run: | - brew install gnu-tar - echo /usr/local/opt/gnu-tar/libexec/gnubin > "$GITHUB_PATH" - - - name: Cache Cargo - uses: actions/cache@v2 - with: - path: | - ~/.cargo/registry - ~/.cargo/git - target - key: ${{ matrix.os }}-${{ matrix.target }} cargo-${{ hashFiles('**/Cargo.lock') }} - - - name: Update Ubuntu Packages - if: ${{ matrix.os == 'ubuntu-latest' }} - run: | - sudo apt-get update - - - name: Install Rust Toolchain - run: | - rustup component add clippy rustfmt - rustup target add ${{ matrix.target }} - rustup default "`cat rust-toolchain`-${{ matrix.target }}" - - - name: Install AArch64 Toolchain - if: ${{ matrix.target == 'aarch64-unknown-linux-gnu' }} - run: sudo apt-get install gcc-aarch64-linux-gnu - - - name: Info - run: | - rustup --version - cargo --version - cargo clippy --version - - - name: Check Lockfile - run: | - cargo update --locked --package just - - - name: Build - run: cargo build --all --target ${{ matrix.target }} - - - name: Test - if: ${{ matrix.native }} - run: cargo test --all --target ${{ matrix.target }} - - - name: Clippy - run: cargo clippy --all --all-targets --all-features - - - name: Format - run: cargo fmt --all -- --check - - - name: Completion Scripts - if: ${{ matrix.os != 'windows-2016' }} - run: | - ./bin/generate-completions - git diff --no-ext-diff --quiet --exit-code - - - name: Check for Forbidden Words - if: ${{ matrix.os == 'ubuntu-latest' }} - run: | - sudo apt-get update - sudo apt-get install ripgrep - ./bin/forbid - - - name: Ref Type - id: ref-type - run: cargo run --package ref-type -- --reference ${{ github.ref }} - - - name: Test Install Script With Explicit Target - if: ${{ matrix.os != 'windows-2016' && steps.ref-type.outputs.value != 'release' }} - run: | - cd "`mktemp -d`" - cat "$GITHUB_WORKSPACE/docs/install.sh" | bash -s -- --target ${{ matrix.target }} --to . - if [[ ${{ matrix.native }} == true ]]; then - ./just --version - fi - - - name: Test Install Script Without Explicit Target - if: ${{ matrix.os != 'windows-2016' && steps.ref-type.outputs.value != 'release' }} - run: | - cd "`mktemp -d`" - cat "$GITHUB_WORKSPACE/docs/install.sh" | bash -s -- --to . - ./just --version - - - name: Package - id: package - if: ${{ startsWith(github.ref, 'refs/tags/') }} - run: ./bin/package ${{github.ref}} ${{matrix.os}} ${{ matrix.target }} - shell: bash - - - name: Publish Archive - uses: softprops/action-gh-release@v0.1.5 - if: ${{ startsWith(github.ref, 'refs/tags/') }} - with: - draft: false - files: ${{ steps.package.outputs.archive }} - prerelease: ${{ steps.ref-type.outputs.value != 'release' }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Publish Changelog - uses: softprops/action-gh-release@v0.1.5 - if: >- - ${{ - startsWith(github.ref, 'refs/tags/') - && matrix.target == 'x86_64-unknown-linux-musl' - }} - with: - draft: false - files: CHANGELOG.md - prerelease: ${{ steps.ref-type.outputs.value != 'release' }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..7825940 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,112 @@ +name: Release + +on: + push: + branches: + - master + tags: + - '*' + +defaults: + run: + shell: bash + +jobs: + all: + name: All + + strategy: + matrix: + target: + - aarch64-unknown-linux-gnu + - armv7-unknown-linux-gnueabihf + - x86_64-apple-darwin + - x86_64-pc-windows-msvc + - x86_64-unknown-linux-musl + include: + - target: aarch64-unknown-linux-gnu + os: ubuntu-latest + native: false + target_rustflags: '--codegen linker=aarch64-linux-gnu-gcc' + - target: armv7-unknown-linux-gnueabihf + os: ubuntu-latest + native: false + target_rustflags: '--codegen linker=arm-linux-gnueabihf-gcc' + - target: x86_64-apple-darwin + os: macos-latest + native: true + target_rustflags: '' + - target: x86_64-pc-windows-msvc + os: windows-2016 + native: true + target_rustflags: '' + - target: x86_64-unknown-linux-musl + os: ubuntu-latest + native: true + target_rustflags: '' + + runs-on: ${{matrix.os}} + + steps: + - uses: actions/checkout@v2 + + - name: Install Rust Toolchain Components + uses: actions-rs/toolchain@v1 + with: + override: true + target: ${{ matrix.target }} + toolchain: stable + + - name: Install AArch64 Toolchain + if: ${{ matrix.target == 'aarch64-unknown-linux-gnu' }} + run: | + sudo apt-get update + sudo apt-get install gcc-aarch64-linux-gnu + + - name: Install ARM7 Toolchain + if: ${{ matrix.target == 'armv7-unknown-linux-gnueabihf' }} + run: | + sudo apt-get update + sudo apt-get install gcc-arm-linux-gnueabihf + + - name: Test + if: matrix.native + run: cargo test --all --target ${{ matrix.target }} + + - name: Ref Type + id: ref-type + run: cargo run --package ref-type -- --reference ${{ github.ref }} + + - name: Package + id: package + env: + TARGET: ${{ matrix.target }} + REF: ${{ github.ref }} + OS: ${{ matrix.os }} + TARGET_RUSTFLAGS: ${{ matrix.target_rustflags }} + run: ./bin/package + shell: bash + + - name: Publish Archive + uses: softprops/action-gh-release@v0.1.5 + if: ${{ startsWith(github.ref, 'refs/tags/') }} + with: + draft: false + files: ${{ steps.package.outputs.archive }} + prerelease: ${{ steps.ref-type.outputs.value != 'release' }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Publish Changelog + uses: softprops/action-gh-release@v0.1.5 + if: >- + ${{ + startsWith(github.ref, 'refs/tags/') + && matrix.target == 'x86_64-unknown-linux-musl' + }} + with: + draft: false + files: CHANGELOG.md + prerelease: ${{ steps.ref-type.outputs.value != 'release' }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..822691a --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,61 @@ +name: Test + +on: pull_request + +defaults: + run: + shell: bash + +jobs: + all: + name: All + + strategy: + matrix: + os: + - ubuntu-latest + - macos-latest + - windows-2016 + + runs-on: ${{matrix.os}} + + env: + RUSTFLAGS: --deny warnings + + steps: + - uses: actions/checkout@v2 + + - name: Install Rust Toolchain Components + uses: actions-rs/toolchain@v1 + with: + components: clippy, rustfmt + override: true + toolchain: 1.47.0 + + - uses: Swatinem/rust-cache@v1 + + - name: Check Lockfile + run: | + cargo update --locked --package just + + - name: Test + run: cargo test --all + + - name: Clippy + run: cargo clippy --all --all-targets + + - name: Format + run: cargo fmt --all -- --check + + - name: Completion Scripts + if: ${{ matrix.os == 'ubuntu-latest' }} + run: | + ./bin/generate-completions + git diff --no-ext-diff --quiet --exit-code + + - name: Check for Forbidden Words + if: ${{ matrix.os == 'ubuntu-latest' }} + run: | + sudo apt-get update + sudo apt-get install ripgrep + ./bin/forbid diff --git a/README.adoc b/README.adoc index 01e61e2..5d41875 100644 --- a/README.adoc +++ b/README.adoc @@ -1829,7 +1829,7 @@ Before merging a particularly large or gruesome change, Janus should be run to m === Minimum Supported Rust Version -The minimum supported Rust version, or MSRV, can be found in link:rust-toolchain[]. +The minimum supported Rust version, or MSRV, is Rust 1.47.0. == Frequently Asked Questions diff --git a/bin/package b/bin/package index 7fe1417..b9e705c 100755 --- a/bin/package +++ b/bin/package @@ -2,49 +2,46 @@ set -euxo pipefail -version=${1#"refs/tags/"} -os=$2 -target=$3 -src=`pwd` -dist=$src/dist -bin=just +VERSION=${REF#"refs/tags/"} +SRC=`pwd` +DIST=$SRC/dist -echo "Packaging $bin $version for $target..." +echo "Packaging just $VERSION for $TARGET..." test -f Cargo.lock || cargo generate-lockfile -echo "Building $bin..." -RUSTFLAGS='--deny warnings --codegen target-feature=+crt-static' \ - cargo build --bin $bin --target $target --release -executable=target/$target/release/$bin +echo "Building just..." +RUSTFLAGS="--deny warnings --codegen target-feature=+crt-static $TARGET_RUSTFLAGS" \ + cargo build --bin just --target $TARGET --release +EXECUTABLE=target/$TARGET/release/just -if [[ $os == windows-2016 ]]; then - executable=$executable.exe +if [[ $OS == windows-2016 ]]; then + EXECUTABLE=$EXECUTABLE.exe fi echo "Copying release files..." mkdir dist cp \ - $executable \ + $EXECUTABLE \ Cargo.lock \ Cargo.toml \ GRAMMAR.md \ LICENSE \ README.adoc \ man/just.1 \ - $dist + $DIST -cd $dist +cd $DIST echo "Creating release archive..." -case $os in +case $OS in ubuntu-latest | macos-latest) - archive=$dist/$bin-$version-$target.tar.gz - tar czf $archive * - echo "::set-output name=archive::$archive" + ARCHIVE=$DIST/just-$VERSION-$TARGET.tar.gz + tar czf $ARCHIVE * + echo "::set-output name=archive::$ARCHIVE" ;; windows-2016) - archive=$dist/$bin-$version-$target.zip - 7z a $archive * - echo "::set-output name=archive::`pwd -W`/$bin-$version-$target.zip" + ARCHIVE=$DIST/just-$VERSION-$TARGET.zip + 7z a $ARCHIVE * + echo "::set-output name=archive::`pwd -W`/just-$VERSION-$TARGET.zip" ;; esac diff --git a/rust-toolchain b/rust-toolchain deleted file mode 100644 index 21998d3..0000000 --- a/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -1.47.0