Skip to content

Commit 4887d82

Browse files
authored
add crates release (#250)
- **Add crates.io release workflow** - **Make idempotent** ## Description ### Why is this change being made? 1. Add a workflow to release crates in order. ### What is changing? 1. Created a new workflow to run integ tests, then release the crates. This uses trusted publishing. ### Related Links - **Issue #, if available**: --- ## Testing ### How was this tested? 1. ### When testing locally, provide testing artifact(s): 1. --- ## Reviewee Checklist **Update the checklist after submitting the PR** - [x] I have reviewed, tested and understand all changes *If not, why:* - [x] I have filled out the Description and Testing sections above *If not, why:* - [x] Build and Unit tests are passing *If not, why:* - [x] Unit test coverage check is passing *If not, why:* - [x] Integration tests pass locally *If not, why:* - [ ] I have updated integration tests (if needed) *If not, why:* - [x] I have ensured no sensitive information is leaking (i.e., no logging of sensitive fields, or otherwise) *If not, why:* - [x] I have added explanatory comments for complex logic, new classes/methods and new tests *If not, why:* - [ ] I have updated README/documentation (if needed) *If not, why:* - [ ] I have clearly called out breaking changes (if any) *If not, why:* --- ## Reviewer Checklist **All reviewers please ensure the following are true before reviewing:** - Reviewee checklist has been accurately filled out - Code changes align with stated purpose in description - Test coverage adequately validates the changes --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent f76ef6f commit 4887d82

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Publish Crates
2+
3+
# Publishes the workspace crates to crates.io after integration tests pass.
4+
# The integration-tests crate is not published (publish = false in its
5+
# Cargo.toml, and it is omitted from the publish list below).
6+
7+
on:
8+
workflow_dispatch:
9+
workflow_call:
10+
11+
env:
12+
CARGO_TERM_COLOR: always
13+
14+
concurrency:
15+
group: publish-crates
16+
cancel-in-progress: false
17+
18+
jobs:
19+
integ:
20+
uses: ./.github/workflows/integration-tests.yml
21+
permissions:
22+
contents: read
23+
id-token: write
24+
pull-requests: write
25+
secrets: inherit
26+
27+
publish:
28+
needs: [integ]
29+
permissions:
30+
contents: read
31+
id-token: write
32+
environment: publish-crates
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Harden Runner
36+
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
37+
with:
38+
egress-policy: audit
39+
40+
- name: Checkout
41+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
42+
with:
43+
fetch-depth: 1
44+
45+
- name: Authenticate to crates.io
46+
uses: rust-lang/crates-io-auth-action@c6f97d42243bad5fab37ca0427f495c86d5b1a18 # v1.0.5
47+
id: auth
48+
49+
- name: Publish crates to crates.io
50+
env:
51+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
52+
run: |
53+
set -euo pipefail
54+
# Publish in dependency (topological) order.
55+
# Before publishing a crate check whether
56+
# its current version is already on crates.io and skip it if so.
57+
crates=(
58+
aws_workload_credentials_provider_common
59+
aws_secretsmanager_caching
60+
aws_certificatemanager_provider
61+
aws_secretsmanager_provider
62+
aws_workload_credentials_provider
63+
)
64+
for crate in "${crates[@]}"; do
65+
version=$(cargo metadata --format-version 1 --no-deps \
66+
| jq -r --arg name "$crate" '.packages[] | select(.name == $name) | .version')
67+
echo "::group::$crate@$version"
68+
69+
http_code=$(curl -sSL -o /dev/null -w '%{http_code}' \
70+
-A "aws-workload-credentials-provider-publish-ci" \
71+
"https://crates.io/api/v1/crates/$crate/$version")
72+
if [[ "$http_code" == "200" ]]; then
73+
echo "$crate@$version already published — skipping"
74+
elif [[ "$http_code" == "404" ]]; then
75+
cargo publish -p "$crate"
76+
else
77+
echo "unexpected HTTP $http_code from crates.io for $crate@$version" >&2
78+
exit 1
79+
fi
80+
echo "::endgroup::"
81+
done

0 commit comments

Comments
 (0)