Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/build_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
artifact_name: python-package

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -33,7 +33,11 @@ jobs:
python -m pip install --upgrade pip
pip install build

- name: Clean dist directory
run: rm -rf dist

- name: Build package
run: python -m build

- name: Upload artifact
uses: actions/upload-artifact@v4
Expand Down
38 changes: 20 additions & 18 deletions .github/workflows/promote_package.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
name: Promote Python Package

on:
workflow_dispatch:
inputs:
package_version:
description: 'Package version to promote (e.g., 0.0.1)'
required: true
type: string
repository_dispatch:
types: [cloudsmith-package-synced]

env:
CLOUDSMITH_NAMESPACE: ${{ vars.CLOUDSMITH_NAMESPACE }}
CLOUDSMITH_STAGING_REPO: 'production'
CLOUDSMITH_PRODUCTION_REPO: 'staging'
CLOUDSMITH_STAGING_REPO: ${{ vars.CLOUDSMITH_STAGING_REPO }}
CLOUDSMITH_PRODUCTION_REPO: ${{ vars.CLOUDSMITH_PRODUCTION_REPO }}
CLOUDSMITH_SERVICE_SLUG: ${{ vars.CLOUDSMITH_SERVICE_SLUG }}
PACKAGE_NAME: 'example_package'

permissions:
id-token: write
Expand All @@ -29,22 +24,29 @@ jobs:
oidc-namespace: ${{ env.CLOUDSMITH_NAMESPACE }}
oidc-service-slug: ${{ env.CLOUDSMITH_SERVICE_SLUG }}

- name: Get package identifier and promote
- name: Query and tag the latest package fetched with 'ready-for-production'
run: |
# Query for the package and get its identifier
PACKAGE_QUERY="filename:${PACKAGE_NAME}-${{ github.event.inputs.package_version }}.tar.gz"
echo "Searching for package with query: $PACKAGE_QUERY"

PACKAGE_NAME="${{ github.event.client_payload.package_name }}"
echo "Webhook received package name: $PACKAGE_NAME"

echo "Fetching latest synced version of $PACKAGE_NAME from Cloudsmith..."

PACKAGE_QUERY="name:$PACKAGE_NAME"
PACKAGE_DATA=$(cloudsmith list package ${{ env.CLOUDSMITH_NAMESPACE }}/${{ env.CLOUDSMITH_STAGING_REPO }} -q "$PACKAGE_QUERY" -F json)


echo "Cloudsmith response for package query : ${PACKAGE_QUERY}"

# Extract the identifier_perm using jq
IDENTIFIER=$(echo "$PACKAGE_DATA" | jq -r '.data[0].identifier_perm')

if [ -z "$IDENTIFIER" ] || [ "$IDENTIFIER" = "null" ]; then
echo "Failed to find package identifier"
echo "No synced package found for $PACKAGE_NAME"
exit 1
fi


echo "Tagging $IDENTIFIER with 'ready-for-production'"
cloudsmith tag add ${{ env.CLOUDSMITH_NAMESPACE }}/${{ env.CLOUDSMITH_STAGING_REPO }}/$IDENTIFIER ready-for-production

echo "Found package identifier: $IDENTIFIER"

# Promote package using the identifier
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/release_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ env:
permissions:
contents: read
actions: read
id-token: write


jobs:
publish:
Expand All @@ -31,8 +33,12 @@ jobs:
repository: ${{ github.repository }}
github-token: ${{ github.token }}
run-id: ${{ github.event.workflow_run.id }}



- name: Authenticate to Cloudsmith
uses: cloudsmith-io/[email protected]
with:
oidc-namespace: ${{ secrets.CLOUDSMITH_NAMESPACE }}
oidc-service-slug: ${{ secrets.CLOUDSMITH_SERVICE_SLUG }}

- name: List directory contents
run: ls -la dist/
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
version = "0.0.5"
name = "example-package"

authors = [
{ name="Example Author", email="author@example.com" },
{ name="Shreya Singh", email="shreyasingh_18@yahoo.com" },
]
description = "A small example package"
readme = "README.md"
Expand All @@ -14,4 +16,4 @@ classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
]