-
Notifications
You must be signed in to change notification settings - Fork 3
130 lines (116 loc) · 4.23 KB
/
pr-preview.yml
File metadata and controls
130 lines (116 loc) · 4.23 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
name: PR Preview
on:
pull_request:
types: [opened, synchronize, ready_for_review]
jobs:
preview:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: '3.x'
# Install all dependencies from pyproject.toml
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install hatchling==1.27.0 hatch==1.14.0
- name: Inject full dynamic version
run: python .hooks/sync_version.py --dev
- name: Check if version exists on Test PyPI
id: version_check
run: |
VERSION=$(hatch version | cut -d+ -f1)
echo "VERSION=$VERSION" >> $GITHUB_ENV
if curl -s -f https://test.pypi.org/pypi/socket-sdk-python/$VERSION/json > /dev/null; then
echo "Version ${VERSION} already exists on Test PyPI"
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "Version ${VERSION} not found on Test PyPI - proceeding with test deployment"
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Clean previous builds
run: rm -rf dist/ build/ *.egg-info
- name: Get Hatch version
id: version
run: |
VERSION=$(hatch version | cut -d+ -f1)
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Build package
if: steps.version_check.outputs.exists != 'true'
run: |
hatch build
- name: Publish to Test PyPI
if: steps.version_check.outputs.exists != 'true'
uses: pypa/gh-action-pypi-publish@v1.12.4
with:
repository-url: https://test.pypi.org/legacy/
verbose: true
- name: Comment on PR
if: steps.version_check.outputs.exists != 'true'
uses: actions/github-script@v7
env:
VERSION: ${{ env.VERSION }}
with:
script: |
const version = process.env.VERSION;
const prNumber = context.payload.pull_request.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
// Find existing bot comments
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const botComment = comments.data.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('🚀 Preview package published!')
);
const comment = `
🚀 Preview package published!
Install with:
\`\`\`bash
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple socket-sdk-python==${version}
\`\`\``;
if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: owner,
repo: repo,
comment_id: botComment.id,
body: comment
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: owner,
repo: repo,
issue_number: prNumber,
body: comment
});
}
- name: Verify package is available
if: steps.version_check.outputs.exists != 'true'
id: verify_package
env:
VERSION: ${{ env.VERSION }}
run: |
for i in {1..30}; do
if pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple socket-sdk-python==${VERSION}; then
echo "Package ${VERSION} is now available and installable on Test PyPI"
pip uninstall -y socket-sdk-python
echo "success=true" >> $GITHUB_OUTPUT
exit 0
fi
echo "Attempt $i: Package not yet installable, waiting 20s... (${i}/30)"
sleep 20
done
echo "success=false" >> $GITHUB_OUTPUT
exit 1