Skip to content

Commit

Permalink
dev: Setup an automated release process (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
olix0r authored Aug 20, 2022
1 parent 713e6ad commit 66ba2d1
Show file tree
Hide file tree
Showing 11 changed files with 343 additions and 28 deletions.
49 changes: 49 additions & 0 deletions .deny.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
targets = [{ triple = "x86_64-unknown-linux-musl" }]

[advisories]
db-path = "~/.cargo/advisory-db"
db-urls = ["https://github.com/rustsec/advisory-db"]
vulnerability = "deny"
unmaintained = "warn"
yanked = "deny"
notice = "warn"
ignore = []

[licenses]
unlicensed = "deny"
allow = ["Apache-2.0", "MIT", "ISC"]
deny = []
copyleft = "deny"
allow-osi-fsf-free = "neither"
default = "deny"
confidence-threshold = 0.8
exceptions = [
# The Unicode-DFS--2016 license is necessary for unicode-ident because they
# use data from the unicode tables to generate the tables which are
# included in the application. We do not distribute those data files so
# this is not a problem for us. See https://github.com/dtolnay/unicode-ident/pull/9/files
# for more details.
{ allow = [
"MIT",
"Apache-2.0",
"Unicode-DFS-2016",
], name = "unicode-ident" },
]


[bans]
multiple-versions = "deny"
wildcards = "deny"
highlight = "all"
deny = []
skip = []
skip-tree = []

[sources]
unknown-registry = "deny"
unknown-git = "deny"
allow-registry = ["https://github.com/rust-lang/crates.io-index"]
allow-git = []

[sources.allow-org]
github = []
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "j52j",
"name": "j5j",
"image": "ghcr.io/linkerd/dev:v30",
"extensions": [
"DavidAnson.vscode-markdownlint",
Expand Down
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2
updates:
- package-ecosystem: cargo
directory: /
schedule:
interval: daily
allow:
- dependency-type: "all"
ignore:
- dependency-name: "clap_derive"

- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
18 changes: 18 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Actions

on:
pull_request:
paths:
- .github/workflows/*

permissions:
contents: read

jobs:
action-lint:
timeout-minutes: 5
runs-on: ubuntu-latest
container: ghcr.io/linkerd/dev:v30-tools
steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
- run: just action-lint
68 changes: 68 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Release

on:
pull_request:
paths:
- .github/workflows/release.yml
push:
tags:
- 'v*'

permissions:
contents: write

env:
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
RUSTFLAGS: "-D warnings"
RUSTUP_MAX_RETRIES: 10

jobs:
meta:
timeout-minutes: 5
runs-on: ubuntu-latest
container: ghcr.io/linkerd/dev:v30-rust
steps:
- id: meta
shell: bash
run: |
set -eu
shopt -s extglob
ref="${{ github.ref }}"
if [[ "$ref" == refs/tags/v+([0-9]).+([0-9]).+([0-9])?(-+([a-z0-9-])) ]]; then
tv=${ref##refs/tags/}
cv=$(just --evaluate version)
if [ "${tv#v}" != "$cv" ]; then
echo "::error ::Crate version v${cv} does not match tag version ${tv}"
exit 1
fi
echo ::set-output name=version::"$tv"
echo ::set-output name=publish::true
else
sha="${{ github.sha }}"
echo ::set-output name=version::"test-${sha:0:7}"
fi
outputs:
publish: ${{ steps.meta.outputs.publish }}
version: ${{ steps.meta.outputs.version }}

package:
needs: [meta]
timeout-minutes: 10
runs-on: ubuntu-latest
container: ghcr.io/linkerd/dev:v30-rust
steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
- run: just fetch
- run: just build
- run: just package

- if: needs.meta.outputs.publish == 'true'
uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
name: ${{ needs.meta.outputs.version }}
files: target/j5j-${{ needs.meta.outputs.version }}-*.tar.gz
generate_release_notes: true

39 changes: 39 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Rust

on:
pull_request:
paths:
- .github/workflows/lint.yml
- Cargo.lock
- '**/*.rs'

permissions:
contents: read

env:
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
RUSTFLAGS: "-D warnings"
RUSTUP_MAX_RETRIES: 10

jobs:
clippy:
timeout-minutes: 5
runs-on: ubuntu-latest
container: ghcr.io/linkerd/dev:v30-rust
steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
- run: just fetch
- run: just clippy

run:
timeout-minutes: 5
runs-on: ubuntu-latest
container: ghcr.io/linkerd/dev:v30-rust
steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
- run: just fetch
- run: |
[ "$(cargo run --frozen --quiet -- .devcontainer/devcontainer.json | jq -r .name)" = j5j ]
- run: |
[ "$(cargo run --frozen --quiet -- - <.devcontainer/devcontainer.json | jq -r .name)" = j5j ]
19 changes: 11 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
[package]
name = "json5-to-json"
version = "0.1.2"
authors = ["Callum Oakley <[email protected]>"]
name = "j5j"
version = "0.2.0"
description = "A bare-bones tool for converting JSON5 to plain JSON."
license = "ISC"
repository = "https://github.com/callum-oakley/json5-to-json"
repository = "https://github.com/olix0r/j5j"
readme = "README.md"
keywords = ["json5", "to", "json", "translate", "convert"]
edition = "2018"
keywords = ["json5", "json", "translate", "convert"]
edition = "2021"

[dependencies]
json5 = "0.2"
serde_json = "1.0"
json5 = "0.4"
serde_json = "1"

[dependencies.clap]
version = "3"
features = ["derive", "env", "std"]
1 change: 1 addition & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Copyright 2022 Oliver Gould
Copyright 2018 Callum Oakley

Permission to use, copy, modify, and/or distribute this software for any
Expand Down
44 changes: 39 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,43 @@
Reads [JSON5][] on stdin, writes plain JSON on stdout. A thin wrapper around
[json5-rs][] and [Serde JSON][].
# j5j

$ cargo install json5-to-json
$ echo "{ hello: 'world' }" | json5-to-json
{"hello":"world"}
Reads [JSON5] from one or more files and prints it as plain old JSON.

Based on `json5-to-json by @callum-oakley.

## Examples

```console
:; j5j .devcontainer/devcontainer.json
{"extensions":["DavidAnson.vscode-markdownlint","kokakiwi.vscode-just","NathanRidley.autotrim","redhat.vscode-yaml","rust-lang.rust-analyzer","samverschueren.final-newline","tamasfe.even-better-toml"],"image":"ghcr.io/linkerd/dev:v30","mounts":["source=/var/run/docker.sock,target=/var/run/docker-host.sock,type=bind"],"name":"j5j","overrideCommand":false,"remoteUser":"code","runArgs":["--init","--memory=12g","--memory-swap=12g","--net=host"]}
```

```console
:; j5j --pretty .devcontainer/devcontainer.json
{
"extensions": [
"DavidAnson.vscode-markdownlint",
"kokakiwi.vscode-just",
"NathanRidley.autotrim",
"redhat.vscode-yaml",
"rust-lang.rust-analyzer",
"samverschueren.final-newline",
"tamasfe.even-better-toml"
],
"image": "ghcr.io/linkerd/dev:v30",
"mounts": [
"source=/var/run/docker.sock,target=/var/run/docker-host.sock,type=bind"
],
"name": "j5j",
"overrideCommand": false,
"remoteUser": "code",
"runArgs": [
"--init",
"--memory=12g",
"--memory-swap=12g",
"--net=host"
]
}
```

[JSON5]: https://json5.org/
[json5-rs]: https://github.com/callum-oakley/json5-rs
Expand Down
52 changes: 52 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

lint: action-lint clippy

##
## Rust
##

# If we're running in github actions and cargo-action-fmt is installed, then add
# a command suffix that formats errors.
_fmt := if env_var_or_default("GITHUB_ACTIONS", "") != "true" { "" } else {
```
if command -v cargo-action-fmt >/dev/null 2>&1; then
echo "--message-format=json | cargo-action-fmt"
fi
```
}

toolchain := ""

_cargo := "cargo" + if toolchain != "" { " +" + toolchain } else { "" }

fetch:
{{ _cargo }} fetch --locked

clippy: fetch
{{ _cargo }} clippy --frozen {{ _fmt }}

build: fetch
{{ _cargo }} build --frozen --release --target x86_64-unknown-linux-musl {{ _fmt }}

version := ```
cargo metadata --format-version=1 \
| jq -r '.packages[] | select(.name == "j5j") | .version' \
| head -n 1
```

package: build
tar -czf target/j5j-v{{ version }}-x86_64-unknown-linux-musl.tar.gz \
-C target/x86_64-unknown-linux-musl/release j5j

##
## Etc
##

# Format actionlint output for Github Actions if running in CI.
_actionlint-fmt := if env_var_or_default("GITHUB_ACTIONS", "") != "true" { "" } else {
'{{range $err := .}}::error file={{$err.Filepath}},line={{$err.Line}},col={{$err.Column}}::{{$err.Message}}%0A```%0A{{replace $err.Snippet "\\n" "%0A"}}%0A```\n{{end}}'
}

# Lints all GitHub Actions workflows
action-lint:
actionlint {{ if _actionlint-fmt != '' { "-format '" + _actionlint-fmt + "'" } else { "" } }} .github/workflows/*
Loading

0 comments on commit 66ba2d1

Please sign in to comment.