-
Notifications
You must be signed in to change notification settings - Fork 3
update(CENG-750): Refresh Circle Orb for Cloudsmith #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
BartoszBlizniak
merged 9 commits into
cloudsmith-io:master
from
BartoszBlizniak:ceng-750-circleci-orb-update
Apr 6, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7409aff
add oidc + cleanup
BartoszBlizniak 86be137
add oidc + cleanup
BartoszBlizniak cb7cfca
add oidc + cleanup
BartoszBlizniak 659ea92
small changes
BartoszBlizniak 8d8c2ea
pipeline fixes
BartoszBlizniak 1acb4b9
make install more readable, seperate into functions
BartoszBlizniak 043c1af
final orb testing
BartoszBlizniak 9e3c7db
set value back to cloudsmith
BartoszBlizniak 5a9d3dd
Use min python required for cloudsmith-cli 3.12 -> 3.10
BartoszBlizniak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,43 +1,67 @@ | ||
| --- | ||
| version: 2.1 | ||
|
|
||
| parameters: | ||
| publish-orb-name: | ||
| type: string | ||
| default: cloudsmith/cloudsmith | ||
|
|
||
| orbs: | ||
| cli: circleci/circleci-cli@0.1.5 | ||
| orb-tools: circleci/orb-tools@8.27.3 | ||
| orb-tools: circleci/orb-tools@12.4.0 | ||
|
|
||
| # Run jobs on all branches and tags | ||
| filters: &filters | ||
| tags: | ||
| only: /.*/ | ||
|
|
||
| jobs: | ||
| publish-orb: | ||
| description: Publishes an orb to CircleCI | ||
| executor: | ||
| cli/default | ||
| steps: | ||
| - attach_workspace: | ||
| at: workspace | ||
| - run: | ||
| name: > | ||
| Publish orb to CircleCI | ||
| command: | | ||
| if [[ -n $CIRCLE_TAG ]]; then | ||
| ORB_REF=$CIRCLE_TAG | ||
| else | ||
| ORB_REF="dev:$CIRCLE_BRANCH" | ||
| fi | ||
| circleci orb publish workspace/orb.yml cloudsmith/cloudsmith@$ORB_REF | ||
| # Run jobs only on semver release tags (e.g. v2.0.0) | ||
| release-filters: &release-filters | ||
| branches: | ||
| ignore: /.*/ | ||
| tags: | ||
| only: /^v[0-9]+\.[0-9]+\.[0-9]+$/ | ||
|
|
||
| workflows: | ||
| verify-and-publish: | ||
| lint-pack-publish: | ||
| jobs: | ||
| # Lint all YAML files in src/ | ||
| - orb-tools/lint: | ||
| filters: | ||
| tags: | ||
| only: /.*/ | ||
| filters: *filters | ||
| # Pack src/ into a single orb.yml and validate it | ||
| - orb-tools/pack: | ||
| filters: *filters | ||
| # Review orb source against CircleCI best practices | ||
| - orb-tools/review: | ||
| filters: *filters | ||
| orb_name: cloudsmith | ||
| # RC009: long inline commands (we use inline bash intentionally) | ||
| # RC010: snake_case naming (our params use kebab-case by convention) | ||
| exclude: RC009,RC010 | ||
| # Publish a dev version on every push (except release tags and PRs) | ||
| - orb-tools/publish: | ||
| name: publish-dev | ||
| orb_name: << pipeline.parameters.publish-orb-name >> | ||
| vcs_type: << pipeline.project.type >> | ||
| pub_type: dev | ||
| context: orb-publishing | ||
| requires: | ||
| - orb-tools/lint | ||
| - orb-tools/pack | ||
| - orb-tools/review | ||
| filters: | ||
| branches: | ||
| ignore: /^pull\/[0-9]+/ | ||
| tags: | ||
| only: /.*/ | ||
| - publish-orb: | ||
| filters: | ||
| tags: | ||
| only: /.*/ | ||
| ignore: /^v[0-9]+\.[0-9]+\.[0-9]+$/ | ||
| # Publish a production version when a semver tag is pushed | ||
| - orb-tools/publish: | ||
| name: publish-production | ||
| orb_name: << pipeline.parameters.publish-orb-name >> | ||
| vcs_type: << pipeline.project.type >> | ||
| pub_type: production | ||
| context: orb-publishing | ||
| requires: | ||
| - orb-tools/lint | ||
| - orb-tools/pack | ||
| - orb-tools/review | ||
| filters: *release-filters |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| extends: default | ||
|
|
||
| rules: | ||
| line-length: | ||
| max: 200 | ||
| truthy: | ||
| check-keys: true | ||
| comments: | ||
| min-spaces-from-content: 1 | ||
| document-start: enable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
BartoszBlizniak marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| version: 2.1 | ||
|
|
||
| description: | | ||
| Install the Cloudsmith CLI and publish packages to Cloudsmith repositories. | ||
| Supports OIDC and API key authentication with configurable CLI options. | ||
|
|
||
| display: | ||
| home_url: https://cloudsmith.io/ | ||
| source_url: https://github.com/cloudsmith-io/orb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,39 +1,102 @@ | ||
| --- | ||
| description: > | ||
| Authenticate with Cloudsmith using OpenID Connect (OIDC) to generate a | ||
| short-lived OIDC token for use in subsequent Cloudsmith requests. This | ||
| short-lived API token for use in subsequent Cloudsmith requests. This | ||
| sets the CLOUDSMITH_API_KEY environment variable to the retrieved token | ||
| for use with the Cloudsmith CLI. | ||
| for use with the Cloudsmith CLI. Retries the token exchange up to | ||
| oidc-auth-retry times (default 3) with a 5-second delay between attempts. | ||
| To use OIDC authentication without installing the CLI, simply call this | ||
| command on its own and omit install-cli from your workflow steps. | ||
| parameters: | ||
| organization: | ||
| type: string | ||
| description: The name of the Cloudsmith organization to use for authentication | ||
| description: > | ||
| The name of the Cloudsmith organization to use for authentication. | ||
| service-account: | ||
| type: string | ||
| description: The name of the Cloudsmith service account to use for authentication | ||
| description: > | ||
| The name of the Cloudsmith service account to use for authentication. | ||
| oidc-audience: | ||
| type: string | ||
| default: "" | ||
| description: > | ||
| Custom audience value sent in the OIDC token exchange request body. | ||
| Leave empty to omit the field and use Cloudsmith's default audience. | ||
| oidc-auth-retry: | ||
| type: integer | ||
| default: 3 | ||
| description: > | ||
| Total number of attempts for the OIDC token exchange. Each retry waits | ||
| 5 seconds before the next attempt. The step fails if all attempts are | ||
| exhausted without a valid token. | ||
| steps: | ||
| - run: | ||
| name: Authenticate to Cloudsmith with OIDC | ||
| command: | | ||
| organization="<<parameters.organization>>" | ||
| service_account="<<parameters.service-account>>" | ||
| oidc_audience="<<parameters.oidc-audience>>" | ||
| max_retries=<<parameters.oidc-auth-retry>> | ||
| oidc_endpoint="https://api.cloudsmith.io/openid/$organization/" | ||
|
|
||
| payload=$(jq -n \ | ||
| # Verify required tools are available | ||
| for cmd in curl jq; do | ||
| if ! command -v "$cmd" > /dev/null; then | ||
| echo "$cmd is required but not found. Ensure it is installed." | ||
| exit 1 | ||
| fi | ||
| done | ||
|
|
||
| if [[ -z "$CIRCLE_OIDC_TOKEN_V2" ]]; then | ||
| echo "CIRCLE_OIDC_TOKEN_V2 is not set." | ||
| echo "Enable OIDC: Project Settings -> Advanced -> Enable OIDC." | ||
| exit 1 | ||
| fi | ||
|
|
||
| attempt=0 | ||
| while [[ $attempt -lt $max_retries ]]; do | ||
| attempt=$((attempt + 1)) | ||
| echo "OIDC authentication attempt $attempt of $max_retries" | ||
|
|
||
| payload=$(jq -n \ | ||
| --arg oidc_token "$CIRCLE_OIDC_TOKEN_V2" \ | ||
| --arg service_slug "$service_account" \ | ||
| '{ | ||
| oidc_token: $oidc_token, | ||
| service_slug: $service_slug | ||
| }' | ||
| ) | ||
| oidc_token: $oidc_token, | ||
| service_slug: $service_slug | ||
| }') | ||
|
|
||
| if [[ -n "$oidc_audience" ]]; then | ||
| payload=$(echo "$payload" | jq \ | ||
| --arg audience "$oidc_audience" \ | ||
| '. + {audience: $audience}') | ||
| fi | ||
|
|
||
| response=$(curl -X POST \ | ||
| response=$(curl -s -X POST \ | ||
| -H "Content-Type: application/json" \ | ||
| -d "$payload" \ | ||
| --silent \ | ||
| "$oidc_endpoint" | ||
| ) | ||
| --write-out '\n%{http_code}' \ | ||
| "$oidc_endpoint") || true | ||
|
|
||
| http_code=$(echo "$response" | tail -n1) | ||
| body=$(echo "$response" | sed '$d') | ||
|
|
||
BartoszBlizniak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if [[ "$http_code" -ge 200 && "$http_code" -lt 300 ]]; then | ||
| token=$(echo "$body" | jq -r '.token // empty') | ||
|
|
||
| if [[ -n "$token" ]]; then | ||
| echo "export CLOUDSMITH_API_KEY=\"$token\"" >> "$BASH_ENV" | ||
| echo "Successfully authenticated with Cloudsmith via OIDC." | ||
| exit 0 | ||
| fi | ||
| fi | ||
|
|
||
| echo "OIDC token exchange failed (attempt $attempt, HTTP $http_code)." | ||
|
|
||
| token=$(echo "$response" | jq -r '.token') | ||
| echo "export CLOUDSMITH_API_KEY=$token" >> "$BASH_ENV" | ||
| source "$BASH_ENV" | ||
| if [[ $attempt -lt $max_retries ]]; then | ||
| echo "Retrying in 5 seconds..." | ||
| sleep 5 | ||
| fi | ||
| done | ||
| echo "OIDC authentication failed after $max_retries attempt(s)." | ||
| exit 1 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.