Skip to content

Commit

Permalink
Chore move utoipa under it's own folder
Browse files Browse the repository at this point in the history
Move utoipa under it's own sub folder from root folder. This gives room
for additional utilities that should be shared across the repo.

Fix Github actions pipeline to support the new project structure.
Replace deprecated cargo `read-manifest` command usage with `metadata`
command.
  • Loading branch information
juhaku committed Aug 25, 2022
1 parent 38158fe commit 567c7e0
Show file tree
Hide file tree
Showing 24 changed files with 153 additions and 161 deletions.
102 changes: 47 additions & 55 deletions .github/actions/publish/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,74 +5,66 @@
token=""
ref=""
while true; do
case $1 in
"--token")
shift
token="$1"
shift
;;
"--ref")
shift
ref=${1/refs\/tags\//}
shift
;;
*)
break
;;
esac
case $1 in
"--token")
shift
token="$1"
shift
;;
"--ref")
shift
ref=${1/refs\/tags\//}
shift
;;
*)
break
;;
esac
done

if [[ "$token" == "" ]]; then
echo "Missing --token <token> option argument, cannot publish crates without it!" && exit 1
echo "Missing --token <token> option argument, cannot publish crates without it!" && exit 1
fi
if [[ "$ref" == "" ]]; then
echo "Missing --ref <ref> option argument, need an explisit ref to release!" && exit 1
echo "Missing --ref <ref> option argument, need an explisit ref to release!" && exit 1
fi

function publish {
module="$1"
if [[ "$module" == "utoipa" ]]; then
cargo publish
else
module="$1"
# echo "publish: $module"
cargo publish -p "$module"
fi
}

if [ ! -f "Cargo.toml" ]; then
echo "Missing Cargo.toml file, not in a Rust project root?" && exit 1
echo "Missing Cargo.toml file, not in a Rust project root?" && exit 1
fi

echo "$token" | cargo login
while read -r module; do
# crate=$(echo "$ref" | sed 's|-[0-9]*\.[0-9]*\.[0-9].*||')
crate=${ref/-[0-9]\.[0-9]\.[0-9]*/}
if [[ "$crate" != "$module" ]]; then
echo "Module: $module does not match to release crate: $crate, skipping release for module"
continue
fi

toml="Cargo.toml"
if [[ "$module" != "utoipa" ]]; then
toml="$module/Cargo.toml"
fi

current_version=$(cargo read-manifest --manifest-path "$toml" | jq -r '.version')
last_version=$(curl -sS https://crates.io/api/v1/crates/"$module"/versions | jq -r '.versions[0].num')
if [[ "$last_version" == "$current_version" ]]; then
echo "Module: $module, is already at it's latest release ($last_version), nothing to release"
continue
fi

echo "Publishing module $module..."
max_retries=10
retry=0
while ! publish "$module" && [[ $retry -lt $max_retries ]]; do
await_time=$((retry*2))
echo "Failed to publish, Retrying $retry... after $await_time sec."
sleep $await_time
retry=$((retry+1))
done
if [[ $retry -eq $max_retries ]]; then
echo "Failed to publish crate $module, try to increase await time? Or retries?" && exit 1
fi
done < <(cargo read-manifest --manifest-path Cargo.toml | jq -r '.metadata.publish.order[]')
# crate=$(echo "$ref" | sed 's|-[0-9]*\.[0-9]*\.[0-9].*||')
crate=${ref/-[0-9]\.[0-9]\.[0-9]*/}
if [[ "$crate" != "$module" ]]; then
echo "Module: $module does not match to release crate: $crate, skipping release for module"
continue
fi

current_version=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name | test("'"$module"'$")) | .version')
last_version=$(curl -sS https://crates.io/api/v1/crates/"$module"/versions | jq -r '.versions[0].num')
if [[ "$last_version" == "$current_version" ]]; then
echo "Module: $module, is already at it's latest release ($last_version), nothing to release"
continue
fi

echo "Publishing module $module..."
max_retries=10
retry=0
while ! publish "$module" && [[ $retry -lt $max_retries ]]; do
await_time=$((retry*2))
echo "Failed to publish, Retrying $retry... after $await_time sec."
sleep $await_time
retry=$((retry+1))
done
if [[ $retry -eq $max_retries ]]; then
echo "Failed to publish crate $module, try to increase await time? Or retries?" && exit 1
fi
done < <(cargo metadata --format-version=1 --no-deps | jq -r '.metadata.publish.order[]')
6 changes: 5 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,28 @@ jobs:
id: changes
run: |
root_changed=false
utoipa_changed=false
gen_changed=false
swagger_changed=false
while read -r change; do
if [[ "$change" == "utoipa-gen" ]]; then
gen_changed=true
elif [[ "$change" == "utoipa-swagger-ui" ]]; then
swagger_changed=true
elif [[ "$change" == "utoipa" ]]; then
utoipa_changed=true
else
root_changed=true
fi
done < <(git diff --name-only ${{ github.sha }}~ ${{ github.sha }} | grep .rs | awk -F \/ '{print $1}')
echo "::set-output name=root_changed::$root_changed"
echo "::set-output name=utoipa_changed::$utoipa_changed"
echo "::set-output name=gen_changed::$gen_changed"
echo "::set-output name=swagger_changed::$swagger_changed"
- name: Run tests
run: |
if [[ "${{ matrix.testset }}" == "utoipa" ]] && [[ ${{ steps.changes.outputs.root_changed }} == true ]]; then
if [[ "${{ matrix.testset }}" == "utoipa" ]] && [[ ${{ steps.changes.outputs.utoipa_changed }} == true ]]; then
cargo test -p utoipa --features openapi_extensions,yaml
elif [[ "${{ matrix.testset }}" == "utoipa-gen" ]] && [[ ${{ steps.changes.outputs.gen_changed }} == true ]]; then
cargo test -p utoipa-gen --features utoipa/actix_extras,chrono,decimal,json,utoipa/uuid,utoipa/json
Expand Down
111 changes: 53 additions & 58 deletions .github/workflows/draft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,68 +19,63 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/checkout@v2
with:
fetch-depth: 0

- uses: ./.github/actions/gitlog
name: Get changed commits
id: gitlog
with:
output-file: ./draft-gitlog.md
crate: ${{ matrix.crate }}
- uses: ./.github/actions/gitlog
name: Get changed commits
id: gitlog
with:
output-file: ./draft-gitlog.md
crate: ${{ matrix.crate }}

- name: Prepare changes
run: |
echo "## What's New :gem: :new: :tada:" > ./draft-changes.md
cat < ./draft-gitlog.md >> ./draft-changes.md
- name: Prepare changes
run: |
echo "## What's New :gem: :new: :tada:" > ./draft-changes.md
cat < ./draft-gitlog.md >> ./draft-changes.md
- name: Get release info
id: release_info
run: |
version=""
if [[ "${{ matrix.crate }}" == "utoipa" ]]; then
version=$(cargo read-manifest | jq -r .version)
else
version=$(cargo read-manifest --manifest-path "${{ matrix.crate }}/Cargo.toml" | jq -r .version)
fi
- name: Get release info
id: release_info
run: |
version=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name | test("'"$module"'$")) | .version')
prerelease=false
if [[ "$version" =~ .*-.* ]]; then
prerelease=true
fi
prerelease=false
if [[ "$version" =~ .*-.* ]]; then
prerelease=true
fi
echo "::set-output name=is_prerelease::$prerelease"
echo "::set-output name=version::$version"
- name: Add full change log link
run: |
echo -e "#### Full [change log](${{ github.server_url }}/${{ github.repository }}/compare/${{ steps.gitlog.outputs.last_release }}...${{ matrix.crate }}-${{ steps.release_info.outputs.version }})" >> ./draft-changes.md
echo "::set-output name=is_prerelease::$prerelease"
echo "::set-output name=version::$version"
- name: Check existing release
id: existing_release
run: |
if git tag | grep -e ^${{ matrix.crate }}-${{ steps.release_info.outputs.version }}$ > /dev/null; then
echo "Tag tag with ${{ matrix.crate }}-${{ steps.release_info.outputs.version }} already exists, cannot draft a release for already existing tag!, Consider upgrading versions to Cargo.toml file"
echo "::set-output name=is_new::false"
else
echo "::set-output name=is_new::true"
fi
- name: Add full change log link
run: |
echo -e "#### Full [change log](${{ github.server_url }}/${{ github.repository }}/compare/${{ steps.gitlog.outputs.last_release }}...${{ matrix.crate }}-${{ steps.release_info.outputs.version }})" >> ./draft-changes.md
- name: Remove previous release
if: ${{ steps.existing_release.outputs.is_new == 'true' }}
run: |
echo ${{ secrets.GITHUB_TOKEN }} | gh auth login --with-token
gh release delete ${{ matrix.crate }}-${{ steps.release_info.outputs.version }} -y || true
- name: Check existing release
id: existing_release
run: |
if git tag | grep -e ^${{ matrix.crate }}-${{ steps.release_info.outputs.version }}$ > /dev/null; then
echo "Tag tag with ${{ matrix.crate }}-${{ steps.release_info.outputs.version }} already exists, cannot draft a release for already existing tag!, Consider upgrading versions to Cargo.toml file"
echo "::set-output name=is_new::false"
else
echo "::set-output name=is_new::true"
fi
- name: Create release
id: create_release
if: ${{ steps.existing_release.outputs.is_new == 'true' }}
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ matrix.crate }}-${{ steps.release_info.outputs.version }}
release_name: ${{ matrix.crate }}-${{ steps.release_info.outputs.version }}
body_path: ./draft-changes.md
draft: true
prerelease: ${{ steps.release_info.outputs.is_prerelease }}
- name: Remove previous release
if: ${{ steps.existing_release.outputs.is_new == 'true' }}
run: |
echo ${{ secrets.GITHUB_TOKEN }} | gh auth login --with-token
gh release delete ${{ matrix.crate }}-${{ steps.release_info.outputs.version }} -y || true
- name: Create release
id: create_release
if: ${{ steps.existing_release.outputs.is_new == 'true' }}
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ matrix.crate }}-${{ steps.release_info.outputs.version }}
release_name: ${{ matrix.crate }}-${{ steps.release_info.outputs.version }}
body_path: ./draft-changes.md
draft: true
prerelease: ${{ steps.release_info.outputs.is_prerelease }}
47 changes: 2 additions & 45 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,57 +1,14 @@
[package]
name = "utoipa"
description = "Compile time generated OpenAPI documentation for Rust"
version = "1.1.0"
edition = "2021"
license = "MIT OR Apache-2.0"
readme = "README.md"
keywords = ["rest-api", "openapi", "auto-generate", "documentation", "compile-time"]
# documentation = ""
# homepage = ""
repository = "https://github.com/juhaku/utoipa"
categories = ["web-programming"]
authors = [
"Juha Kukkonen <[email protected]>"
]

exclude = [
".git*",
".github"
]

[features]
default = ["json"]
debug = ["utoipa-gen/debug"]
actix_extras = ["utoipa-gen/actix_extras"]
rocket_extras = ["utoipa-gen/rocket_extras"]
axum_extras = ["utoipa-gen/axum_extras"]
json = ["serde_json", "utoipa-gen/json"]
chrono = ["utoipa-gen/chrono"]
chrono_with_format = ["utoipa-gen/chrono_with_format"]
decimal = ["utoipa-gen/decimal"]
yaml = ["serde_yaml", "utoipa-gen/yaml"]
uuid = ["utoipa-gen/uuid"]
time = ["utoipa-gen/time"]
smallvec = ["utoipa-gen/smallvec"]
openapi_extensions = []

[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", optional = true }
serde_yaml = { version = "0.9", optional = true }
utoipa-gen = { version = "1.1.0", path = "./utoipa-gen" }

[dev-dependencies]
assert-json-diff = "2"

[workspace]
members = [
"utoipa",
"utoipa-gen",
"utoipa-swagger-ui"
]

[package.metadata.docs.rs]
features = ["json", "actix_extras"]

[package.metadata.publish]
[workspace.metadata.publish]
order = ["utoipa-gen", "utoipa", "utoipa-swagger-ui"]
2 changes: 1 addition & 1 deletion utoipa-gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ lazy_static = { version = "1.4", optional = true }
uuid = { version = "1", optional = true }

[dev-dependencies]
utoipa = { path = "..", default-features = false }
utoipa = { path = "../utoipa", default-features = false }
serde_json = "1"
serde = "1"
actix-web = { version = "4", features = [ "macros" ], default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion utoipa-swagger-ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mime_guess = { version = "2.0" }
actix-web = { version = "4", features = [ "macros" ], optional = true, default-features = false }
rocket = { version = "0.5.0-rc.1", features = ["json"], optional = true }
axum = { version = "0.5", optional = true }
utoipa = { version = "1", path = "..", default-features = false, features = [] }
utoipa = { version = "1", path = "../utoipa", default-features = false, features = [] }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0" }

Expand Down
44 changes: 44 additions & 0 deletions utoipa/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
name = "utoipa"
description = "Compile time generated OpenAPI documentation for Rust"
version = "1.1.0"
edition = "2021"
license = "MIT OR Apache-2.0"
readme = "README.md"
keywords = ["rest-api", "openapi", "auto-generate", "documentation", "compile-time"]
# documentation = ""
# homepage = ""
repository = "https://github.com/juhaku/utoipa"
categories = ["web-programming"]
authors = [
"Juha Kukkonen <[email protected]>"
]

[features]
default = ["json"]
debug = ["utoipa-gen/debug"]
actix_extras = ["utoipa-gen/actix_extras"]
rocket_extras = ["utoipa-gen/rocket_extras"]
axum_extras = ["utoipa-gen/axum_extras"]
json = ["serde_json", "utoipa-gen/json"]
chrono = ["utoipa-gen/chrono"]
chrono_with_format = ["utoipa-gen/chrono_with_format"]
decimal = ["utoipa-gen/decimal"]
yaml = ["serde_yaml", "utoipa-gen/yaml"]
uuid = ["utoipa-gen/uuid"]
time = ["utoipa-gen/time"]
smallvec = ["utoipa-gen/smallvec"]
openapi_extensions = []

[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", optional = true }
serde_yaml = { version = "0.9", optional = true }
utoipa-gen = { version = "1.1.0", path = "../utoipa-gen" }

[dev-dependencies]
assert-json-diff = "2"

[package.metadata.docs.rs]
features = ["json", "actix_extras", "axum_extras"]

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 567c7e0

Please sign in to comment.