Skip to content

Commit

Permalink
v1.0.3: Rename the action to olix0r/cargo-action-fmt/setup@v2 (#130)
Browse files Browse the repository at this point in the history
* Update the action workflow to use (new) tarballed release artifacts
* Update the README to fix examples and explicitly note current
  shortcomings with regard to `cargo fmt` and `cargo test`
* Add a `justfile` to make the release workflow easier to test.
* Add a separate workflow for action releases.
  • Loading branch information
olix0r committed Dec 4, 2022
1 parent 30514d7 commit 5e7f934
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 144 deletions.
20 changes: 5 additions & 15 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,29 @@ on:
- "**/*.rs"
- .github/workflows/lint.yml

env:
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
RUST_BACKTRACE: short
RUSTUP_MAX_RETRIES: 10

jobs:
clippy:
timeout-minutes: 10
runs-on: ubuntu-latest
container: docker://ghcr.io/linkerd/dev:v36-rust
steps:
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
- uses: ./
- run: cargo fetch
- run: rustup component add clippy
- run: cargo clippy --message-format=json | cargo-action-fmt
- run: just-cargo fetch --locked
- run: just-cargo clippy

fmt:
timeout-minutes: 10
runs-on: ubuntu-latest
container: docker://ghcr.io/linkerd/dev:v36-rust
steps:
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
- run: rustup component add rustfmt
- run: cargo fmt --check
- run: just-cargo fmt --check

docs:
timeout-minutes: 10
runs-on: ubuntu-latest
container: docker://ghcr.io/linkerd/dev:v36-rust
steps:
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
- uses: ./
- run: cargo fetch
- run: cargo doc --no-deps --message-format=json | cargo-action-fmt
- run: just-cargo fetch
- run: just-cargo doc --no-deps
68 changes: 68 additions & 0 deletions .github/workflows/release-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Action Release

on:
pull_request:
paths:
- .github/workflows/release-actionml
- setup/action.yml
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'

permissions:
contents: write

jobs:
publish:
runs-on: ubuntu-latest
timeout-minutes: 10
container: docker://ghcr.io/linkerd/dev:v36-rust
steps:
- name: Parse tag
id: parse-tag
shell: bash
run: |
ref="${{ github.ref }}"
if [[ "$ref" == refs/tags/v* ]]; then
v="${ref#refs/tags/}"
echo "Action version: $v"
echo version="$v" >> "$GITHUB_OUTPUT"
else
echo "Not a release version: $ref"
fi
# XXX dev:v36-rust container doesn't include libjq
- run: apt update && apt install -y --no-install-recommends jq

- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
- run: just fetch --locked

- name: Check that the action references the current crate version
run: |
action=$(yq .inputs.version.default setup/action.yml)
echo "setup/action.yml $action"
crate=$(just crate-version)
echo "Cargo.toml $crate"
if [ "${crate}" != "${action}" ]; then
echo "::error ::Action version ${action} does not match the current crate version ${crate}"
exit 1
fi
# Exercise the action to ensure it works as expected
- uses: ./setup
id: setup
- name: Check that setup-provided binary is first in the PATH
run: |
bin=$(command -v cargo-action-fmt)
if [ "$bin" != '${{ steps.setup.outputs.bin }}' ]; then
echo "::error ::cargo-action-fmt is not installed in the expected location"
exit 1
fi
- name: Check that it's usable
run: cargo check -q --message-format=json | cargo-action-fmt

- uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5
if: steps.parse-tag.outputs.version
with:
name: setup@${{ steps.parse-tag.outputs.version }}
generate_release_notes: true
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
name: release
name: Crate Release

on:
pull_request:
paths:
- .github/workflows/release.yml
- action.yml
- .github/workflows/release-crate.yml
- Cargo.toml
- justfile
push:
tags:
- 'release/*'
- 'release/v[0-9]+.[0-9]+.[0-9]+'

permissions:
contents: write

env:
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
RUST_BACKTRACE: short
RUSTUP_MAX_RETRIES: 10

jobs:
publish:
runs-on: ubuntu-latest
Expand All @@ -32,7 +26,7 @@ jobs:
ref="${{ github.ref }}"
if [[ "$ref" == refs/tags/release/* ]]; then
v="${ref#refs/tags/release/}"
echo "Release version: $v"
echo "Crate version: $v"
echo version="$v" >> "$GITHUB_OUTPUT"
else
echo "Not a release version: $ref"
Expand All @@ -42,37 +36,25 @@ jobs:
- run: apt update && apt install -y --no-install-recommends jq

- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
- name: Check action version
if: steps.parse-tag.outputs.version
run: |
v=$(yq .inputs.version.default action.yml)
echo "action.yml $v"
if [ "${v}" != '${{ steps.parse-tag.outputs.version }}' ]; then
echo "::error ::Action version ${v} does not match tag version ${{ steps.parse-tag.outputs.version }}"
exit 1
fi
- run: just fetch --locked

- run: just-cargo fetch --locked
- name: Check crate version
if: steps.parse-tag.outputs.version
run: |
v=$(just-cargo crate-version 'cargo-action-fmt')
v=$(just crate-version)
echo "cargo.toml $v"
if [ "${v}" != '${{ steps.parse-tag.outputs.version }}' ]; then
echo "::error ::Crate version v${v} does not match tag version ${{ steps.parse-tag.outputs.version }}"
echo "::error ::Crate version '${v} does' not match tag version '${{ steps.parse-tag.outputs.version }}'"
exit 1
fi
- run: just-cargo profile=release target=x86_64-unknown-linux-musl build --frozen
- run: just-cargo profile=release target=aarch64-unknown-linux-musl build --frozen
- run: just-cargo profile=release target=armv7-unknown-linux-musleabihf build --frozen
- name: Package
shell: bash
run: |
mkdir -p target/out
for t in {x86_64,aarch64}-unknown-linux-musl armv7-unknown-linux-musleabihf ; do
tar czf "target/out/cargo-action-fmt-${t}.tar.gz" -C "target/$t/release" cargo-action-fmt
done
# These are fairly quick so we don't bother running them in parallel. The
# `cargo fetch` time above far outweighs the build time.
- run: echo PKG_DIR="$(mktemp -d "$RUNNER_TEMP/pkg.XXX")" >> "$GITHUB_ENV"
- run: just profile=release target=x86_64-unknown-linux-musl package "$PKG_DIR"
- run: just profile=release target=aarch64-unknown-linux-musl package "$PKG_DIR"
- run: just profile=release target=armv7-unknown-linux-musleabihf package "$PKG_DIR"
- run: find "$PKG_DIR"/release -ls

- if: steps.parse-tag.outputs.version == ''
run: cargo publish --dry-run
Expand All @@ -83,5 +65,5 @@ jobs:
if: steps.parse-tag.outputs.version
with:
name: ${{ steps.parse-tag.outputs.version }}
files: target/out/*
files: ${{ env.PKG_DIR }}/release/*
generate_release_notes: true
27 changes: 0 additions & 27 deletions .github/workflows/rustsec.yml

This file was deleted.

45 changes: 6 additions & 39 deletions .github/workflows/toolchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,17 @@ on:
permissions:
contents: read

env:
YQ_VERSION: v4.2.0

jobs:
dockerfiles:
dev-action-images:
runs-on: ubuntu-latest
steps:
- uses: linkerd/dev/actions/setup-tools@v36
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
- run: |
VERSION="$(cat rust-toolchain)"
ex=0
for f in $(find . -name Dockerfile -and -not -path './.github/actions/release-tag-meta/*'); do
versions=$(sed -nE 's/^ARG RUST_VERSION=([^ ]+)/\1/p' $f)
if [ -z "$versions" ]; then
echo "::error file=$f::$f missing 'RUST_VERSION' argument"
ex=$((ex + 1))
fi
for mismatch in $(echo "$version" | grep -vF "$VERSION" || true) ; do
echo "::error file=$f::$f uses incorrect rust version(s): $mismatch"
ex=$((ex + 1))
done
done
exit $ex
- run: just-dev check-action-images

workflows:
lint-actions:
runs-on: ubuntu-latest
steps:
- uses: linkerd/dev/actions/setup-tools@v36
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
- run: |
curl --proto '=https' --tlsv1.3 -vsSfLo /usr/local/bin/yq "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64" \
&& chmod +x /usr/local/bin/yq
- run: |
VERSION="$(cat rust-toolchain)"
ex=0
for f in $(find .github/workflows -name '*.yml') ; do
echo "# $f"
for image in $(yq eval '.jobs[].container.image' $f) ; do
if [[ "$image" =~ "^docker://(docker.io/library/)?rust:" ]]; then
v="${${image##*rust:}%%-*}"
if [[ "$v" != "$VERSION" ]]; then
echo "::warning file=$f::$f uses incorrect rust version: $v"
ex=$((ex + 1))
fi
fi
done
done
exit $ex
- run: just-dev lint-actions
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-action-fmt"
version = "1.0.2"
version = "1.0.3"
edition = "2021"
license = "MIT"
repository = "https://github.com/olix0r/cargo-action-fmt"
Expand Down
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
# `cargo-action-fmt`

Takes JSON-formatted `cargo check` (and `cargo clippy`) output and formats it for GitHub actions.
Takes JSON-formatted `cargo check` (and `cargo clippy`) output and formats it
for GitHub actions.

### Examples
## Examples

This tool can be used with a variety of `cargo` commands:

```shell
:; cargo check -q --message-format=json | clippy-action-fmt
:; cargo check -q --message-format=json | cargo-action-fmt
```

```shell
:; cargo clippy -q --message-format=json | clippy-action-fmt
:; cargo clippy -q --message-format=json | cargo-action-fmt
```

```shell
:; cargo doc --message-format=json | clippy-action-fmt
:; cargo doc --message-format=json | cargo-action-fmt
```

Note that this tool does **not** currently support `cargo fmt` or `cargo test`
output. However, you can invoke `cargo test` so that test compilation errors are
annotated properly:

```shell
:; cargo test --no-run --message-format=json | cargo-action-fmt
```

### GitHub Action

It's primarily intended to be used in a GitHub Actions workflow:

```yaml
docs:
timeout-minutes: 10
runs-on: ubuntu-latest
container:
image: docker://rust:1.60-bullseye
container: rust:slim
steps:
- uses: olix0r/cargo-action-fmt@v1.0.1
- uses: olix0r/cargo-action-fmt/setup@v2
- uses: actions/checkout@v2
- run: cargo doc --no-deps --message-format=json | cargo-action-fmt
```
Expand Down
18 changes: 0 additions & 18 deletions action.yml

This file was deleted.

18 changes: 18 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Defaults for development.
profile := 'debug'
target := 'x86_64-unknown-linux-gnu'

fetch *args:
@just-cargo fetch {{ args }}

build *args:
@just-cargo profile={{ profile }} target={{ target }} build --frozen {{ args }}

package dir: build
@mkdir -p '{{ dir }}/{{ profile }}'
tar czf '{{ dir }}/{{ profile }}/cargo-action-fmt-{{ target }}.tar.gz' \
-C 'target/{{ target }}/{{ profile }}' \
cargo-action-fmt

crate-version:
@just-cargo crate-version 'cargo-action-fmt'
Loading

0 comments on commit 5e7f934

Please sign in to comment.