-
Notifications
You must be signed in to change notification settings - Fork 6
171 lines (135 loc) · 6.03 KB
/
release-internal.yml
File metadata and controls
171 lines (135 loc) · 6.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
name: Publish Package to Internal Artifactory
on:
pull_request:
branches:
- main
types: [opened, synchronize, reopened]
jobs:
publish:
name: Publish to Artifactory
runs-on: ["self-hosted"]
environment: 'artifactory:sap-cloud-sdk'
if: ${{ !contains(github.server_url, 'github.com') }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
- name: Read package name and version from pyproject.toml
id: metadata
run: |
pip install toml
PKG_NAME=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['name'])")
BASE_VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])")
echo "Base version: $BASE_VERSION"
echo "name=$PKG_NAME" >> $GITHUB_OUTPUT
echo "base_version=$BASE_VERSION" >> $GITHUB_OUTPUT
- name: Generate prerelease version
id: prerelease
run: |
BASE_VERSION="${{ steps.metadata.outputs.base_version }}"
# Get current date in YYYYMMDD format
DATE=$(date +%Y%m%d)
# Get branch name and sanitize it (remove refs/heads/ prefix and replace / with -)
BRANCH_NAME="${{ github.head_ref || github.ref_name }}"
BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/refs\/heads\///' | sed 's/\//-/g')
# Get short commit SHA
SHORT_SHA="${{ github.event.pull_request.head.sha || github.sha }}"
SHORT_SHA=${SHORT_SHA:0:7}
# Create PEP 440-compliant prerelease version
# Format: X.Y.Z.devYYYYMMDD+branch.sha
PRERELEASE_VERSION="${BASE_VERSION}.dev${DATE}+${BRANCH_NAME}.${SHORT_SHA}"
echo "Generated prerelease version: $PRERELEASE_VERSION"
echo "version=$PRERELEASE_VERSION" >> $GITHUB_OUTPUT
- name: Update version in pyproject.toml
run: |
PRERELEASE_VERSION="${{ steps.prerelease.outputs.version }}"
# Update version in pyproject.toml
python -c "
import toml
data = toml.load('pyproject.toml')
data['project']['version'] = '$PRERELEASE_VERSION'
with open('pyproject.toml', 'w') as f:
toml.dump(data, f)
"
echo "Updated pyproject.toml with version: $PRERELEASE_VERSION"
- name: Check if version already exists in Artifactory
env:
REPOSITORY_NAME: ${{ vars.REPOSITORY_NAME }}
ARTIFACTORY_URL: ${{ vars.ARTIFACTORY_URL }}
ARTIFACTORY_USER: ${{ secrets.ARTIFACTORY_USER }}
ARTIFACTORY_TOKEN: ${{ secrets.ARTIFACTORY_TOKEN }}
run: |
PKG_NAME="${{ steps.metadata.outputs.name }}"
VERSION="${{ steps.prerelease.outputs.version }}"
echo "Checking if $PKG_NAME version $VERSION exists in Artifactory..."
# Convert package name to filename format (replace hyphens with underscores)
PKG_FILE_NAME=$(echo "$PKG_NAME" | sed 's/-/_/g')
FILE_PATH="$ARTIFACTORY_URL/$REPOSITORY_NAME/$PKG_NAME/$VERSION/${PKG_FILE_NAME}-${VERSION}.tar.gz"
echo "Checking for file: $FILE_PATH"
# Check if file exists using HEAD request
HTTP_STATUS=$(curl -I -s -o /dev/null -w "%{http_code}" \
-u "$ARTIFACTORY_USER:$ARTIFACTORY_TOKEN" \
"$FILE_PATH")
if [ "$HTTP_STATUS" = "200" ]; then
echo "ERROR: Version $VERSION of $PKG_NAME already exists in Artifactory!"
echo "File found: $FILE_PATH"
echo "Please increment the version in pyproject.toml before publishing."
exit 1
else
echo "Version $VERSION is available for upload to Artifactory"
fi
- name: Build release distribution
run: uv build
- name: Publish to Artifactory
env:
REPOSITORY_NAME: ${{ vars.REPOSITORY_NAME }}
ARTIFACTORY_URL: ${{ vars.ARTIFACTORY_URL }}
ARTIFACTORY_USER: ${{ secrets.ARTIFACTORY_USER }}
ARTIFACTORY_TOKEN: ${{ secrets.ARTIFACTORY_TOKEN }}
run: |
PKG_NAME="${{ steps.metadata.outputs.name }}"
VERSION="${{ steps.prerelease.outputs.version }}"
echo "Publishing to Artifactory..."
echo "Repository URL: $ARTIFACTORY_URL/api/pypi/$REPOSITORY_NAME/"
uv publish \
--publish-url "$ARTIFACTORY_URL/api/pypi/$REPOSITORY_NAME/" \
--username "$ARTIFACTORY_USER" \
--password "$ARTIFACTORY_TOKEN" \
dist/*
echo "Successfully published $PKG_NAME version $VERSION to Artifactory!"
- name: Generate Installation Summary
if: success()
env:
REPOSITORY_NAME: ${{ vars.REPOSITORY_NAME }}
ARTIFACTORY_URL: ${{ vars.ARTIFACTORY_URL }}
run: |
PKG_NAME="${{ steps.metadata.outputs.name }}"
VERSION="${{ steps.prerelease.outputs.version }}"
BASE_VERSION="${{ steps.metadata.outputs.base_version }}"
# Write to GitHub Step Summary
cat >> $GITHUB_STEP_SUMMARY <<EOF
## ✅ Package Published Successfully
**Package:** \`$PKG_NAME\`
**Version:** \`$VERSION\`
**Base Version:** \`$BASE_VERSION\`
**Repository:** $ARTIFACTORY_URL/artifactory/api/pypi/$REPOSITORY_NAME/
---
## 📦 Installation Instructions
\`\`\`bash
# uv
uv add $PKG_NAME==$VERSION --index $ARTIFACTORY_URL/artifactory/api/pypi/$REPOSITORY_NAME/simple/
# Poetry
poetry add $PKG_NAME==$VERSION --source $ARTIFACTORY_URL/artifactory/api/pypi/$REPOSITORY_NAME/simple/
# Pip
pip install $PKG_NAME==$VERSION --index-url $ARTIFACTORY_URL/artifactory/api/pypi/$REPOSITORY_NAME/simple/
\`\`\`
---
*Published at: $(date -u '+%Y-%m-%d %H:%M:%S UTC')*
EOF