diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5f22296a..b0cdd582 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -135,3 +135,37 @@ jobs: # Check that the release automation works as expected - run: scripts/release/test.sh + + # Check that the Github Action works + github-action-test: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + # Make sure we cover all operating systems supported by Github Actions + os: + - windows-2019 + - windows-2022 + - ubuntu-20.04 + - ubuntu-22.04 + - macos-13 + - macos-12 + - macos-11 + + steps: + - uses: actions/checkout@v4 + + # This action downloads the latest released version of `cargo-marker`, + # and installs it into `$PATH`. + # + # Because `marker_lints` in this repo depends on the next dev version of + # `marker_api` it won't be compatible with the latest released `marker_api`, + # so there is no sense in actually running `cargo marker check` here. + # Therefore we set `install-only` to skip running a command. + - uses: ./ + with: + install-only: true + + # +stable is to force using the pre-installed `cargo` on the runner instead of + # what's specified in `rust-toolchain.toml` + - run: cargo +stable marker --version diff --git a/action.yml b/action.yml new file mode 100644 index 00000000..442b7e7a --- /dev/null +++ b/action.yml @@ -0,0 +1,37 @@ +name: marker +description: GitHub Action for installing and running Marker linting +branding: + icon: edit-3 + color: white + +inputs: + command: + description: > + CLI arguments that will be appended to `cargo marker` command. + By default `cargo marker check` will be run. + This is mutually exclusive with `install-only`. + + default: check + required: false + + install-only: + description: > + If set to `true` then the action will only install `cargo marker`, + and will skip running the `command`. This is mutually exclusive with `command`. + + default: 'false' + required: false + +runs: + using: composite + steps: + - run: ${GITHUB_ACTION_PATH:?}/scripts/release/install.${{ runner.os == 'Windows' && 'ps1' || 'sh' }} + shell: bash + + - run: cargo marker $COMMAND + if: ${{ inputs.install-only == 'false' }} + env: + # Put the command into the environment variable to prevent script injection and just allow + # passing arguments to the command. + COMMAND: ${{ inputs.command }} + shell: bash diff --git a/scripts/release/install.ps1 b/scripts/release/install.ps1 index 3df360be..35291d5a 100644 --- a/scripts/release/install.ps1 +++ b/scripts/release/install.ps1 @@ -1,3 +1,5 @@ +#!/usr/bin/env powershell +# # This script downloads the `cargo-marker` and the `marker_rustc_driver` # binaries from the GitHub release assets. It also sets up the required # Rust toolchain that the `marker_rustc_driver` depends on. @@ -20,7 +22,7 @@ $ErrorActionPreference = "Stop" # This script isn't meant to be run from `master`, but if it is, then # it will install the latest version be it a stable version or a pre-release. # region replace-version unstable -$version = "0.2.1" +$version = "0.3.0" # endregion replace-version unstable $toolchain = "nightly-2023-08-24" @@ -34,7 +36,7 @@ function With-Log { & $cmd @rest } -function Extract-TarGz { +function Unzip { param ( [string]$bin, [string]$dest @@ -43,9 +45,22 @@ function Extract-TarGz { With-Log cd $temp_dir - Check-Sha256Sum $file_stem "tar.gz" + Check-Sha256Sum $file_stem "zip" - With-Log tar --extract --file (Join-Path $temp_dir "$file_stem.tar.gz") --directory $dest + # There is `tar` on Windows installed by default, but it looks like different + # environments have extremely different variations of tar installed. + # + # For example, my home laptop with Windows 11 has `bsdtar 3.5.2` installed. + # It works fine with Windows paths out of the box. However, Windows Github Actions + # runner has `tar (GNU tar) 1.34`, which somehow doesn't work with Windows paths. + # It just doesn't eat a path with a driver letter and says "No such file or directory". + # + # Anyway, there is so much inconsistency between home windows and Github Actions, that + # it's just easier to use the PowerShell builtin unzip utility that has always been there. + With-Log Expand-Archive ` + -Force ` + -LiteralPath (Join-Path $temp_dir "$file_stem.zip") ` + -DestinationPath $dest } # There isn't mktemp on Windows, so we have to reinvent the wheel. @@ -103,6 +118,8 @@ $exe = if ([System.Environment]::OSVersion.Platform -eq "Win32NT") { "" } +With-Log curl$exe --version + With-Log rustup install --profile minimal --no-self-update $toolchain $host_triple = ( @@ -115,7 +132,7 @@ $current_dir = (Get-Location).Path $temp_dir = New-TemporaryDirectory try { - $files = "{cargo-marker,marker_rustc_driver}-$host_triple.{tar.gz,sha256}" + $files = "{cargo-marker,marker_rustc_driver}-$host_triple.{zip,sha256}" # Curl is available by default on windows, yay! # https://curl.se/windows/microsoft.html @@ -130,7 +147,7 @@ try { --retry-connrefused ` --remote-name ` --output-dir $temp_dir ` - "https://github.com/rust-marker/marker/releases/download/v$version/$files" + "https://github.com/Veetaha/marker/releases/download/v$version/$files" # There is a null coalescing operator in PowerShell 7, but that version # is too cutting edge for now. @@ -140,10 +157,12 @@ try { Join-Path $HOME ".cargo" } - Extract-TarGz "cargo-marker" (Join-Path $cargo_home "bin") + Unzip "cargo-marker" (Join-Path $cargo_home "bin") $sysroot = (rustc +$toolchain --print sysroot) - Extract-TarGz "marker_rustc_driver" (Join-Path $sysroot "bin") + Unzip "marker_rustc_driver" (Join-Path $sysroot "bin") + + With-Log cargo +$toolchain marker --version } finally { Write-Output "Removing the temp directory $temp_dir" diff --git a/scripts/release/install.sh b/scripts/release/install.sh index 7c4e024e..0ec5eb50 100755 --- a/scripts/release/install.sh +++ b/scripts/release/install.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +# # This script downloads the `cargo-marker` and the `marker_rustc_driver` # binaries from the GitHub release assets. It also sets up the required # Rust toolchain that the `marker_rustc_driver` depends on. @@ -16,7 +17,7 @@ set -Eeuo pipefail # This script isn't meant to be run from `master`, but if it is, then # it will install the latest version be it a stable version or a pre-release. # region replace-version unstable -version=0.2.1 +version=0.3.0 # endregion replace-version unstable toolchain=nightly-2023-08-24 @@ -26,11 +27,20 @@ function with_log { "$@" } +with_log curl --version +with_log grep --version +with_log tar --version + with_log rustup install --profile minimal --no-self-update $toolchain +# MacOS uses some shitty BSD grep by default, and there isn't support for +# `--perl-regexp` option there, so we have to go without using that. +# +# Example env where it doesn't work are `macos-11` and `macos-12` Github Actions runners. host_triple=$(\ - rustc +$toolchain --version --verbose \ - | grep --only-matching --perl-regexp 'host: \K.*' \ + rustc "+$toolchain" --version --verbose \ + | grep --only-matching 'host: .*' \ + | grep --only-matching '[^ ]*$' ) trap cleanup SIGINT SIGTERM ERR EXIT @@ -47,6 +57,10 @@ function cleanup { files="{cargo-marker,marker_rustc_driver}-$host_triple.{tar.gz,sha256}" # Download all files using a single TCP connection with HTTP2 multiplexing +# Unfortunately, `curl 7.68.0` installed on Ubuntu 20.04 Github Actions runner +# doesn't have the `--output-dir` option (it was added in `7.73.0`), so we have +# to do an explicit `pushd/popd` for the temp directory. +with_log pushd "$temp_dir" with_log curl \ --location \ --silent \ @@ -55,8 +69,8 @@ with_log curl \ --retry 5 \ --retry-connrefused \ --remote-name \ - --output-dir "$temp_dir" \ - "https://github.com/rust-marker/marker/releases/download/v$version/$files" + "https://github.com/Veetaha/marker/releases/download/v$version/$files" +with_log popd function extract_archive { local bin="$1" @@ -65,11 +79,21 @@ function extract_archive { # `--ignore-missing` because the `sha256` file also includes the checksum for `zip` archive, # but we only download the `tar.gz` one. - (with_log cd $temp_dir && with_log sha256sum --ignore-missing --check "$file_stem".sha256) - - with_log tar --extract --file "$temp_dir/$file_stem.tar.gz" --directory "$dest" + # + # On MacOS there isn't `sha256sum` command, but there is `shasum` which is compatible. + (with_log cd $temp_dir && with_log shasum --ignore-missing --check "$file_stem".sha256) + + # On Windows we also have `--force-local` here (see the reasoning for that in the PowerShell script). + # However, here we don't use this although it wouldn't hurt, but `bsdtar 3.5.1` on MacOS doesn't + # support this option. + with_log tar \ + --extract \ + --file "$temp_dir/$file_stem.tar.gz" \ + --directory "$dest" } extract_archive cargo-marker "${CARGO_HOME-$HOME/.cargo}/bin" -extract_archive marker_rustc_driver "$(rustc +$toolchain --print sysroot)/bin" +extract_archive marker_rustc_driver "$(rustc "+$toolchain" --print sysroot)/bin" + +with_log cargo "+$toolchain" marker --version