-
Notifications
You must be signed in to change notification settings - Fork 2
116 lines (102 loc) · 4.06 KB
/
Copy pathrelease-preview.yml
File metadata and controls
116 lines (102 loc) · 4.06 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
# Preview release info on PRs to main
name: Release Preview
on:
pull_request:
branches: [main]
jobs:
preview:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
- name: Set up Python
run: uv python install 3.11
- name: Get version from pyproject.toml
id: version
run: |
VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Check if tag exists
id: check_tag
run: |
if git rev-parse "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Check PyPI for existing version
id: check_pypi
run: |
VERSION="${{ steps.version.outputs.version }}"
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "https://pypi.org/pypi/late-sdk/$VERSION/json")
if [ "$HTTP_STATUS" = "200" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Create PR Comment
uses: actions/github-script@v7
with:
script: |
const version = '${{ steps.version.outputs.version }}';
const tagExists = '${{ steps.check_tag.outputs.exists }}' === 'true';
const pypiExists = '${{ steps.check_pypi.outputs.exists }}' === 'true';
let body = '## 📦 Release Preview\n\n';
body += '| Item | Value |\n';
body += '|------|-------|\n';
body += `| Version | \`${version}\` |\n`;
body += `| Git tag exists | ${tagExists ? '✅ Yes' : '❌ No'} |\n`;
body += `| PyPI version exists | ${pypiExists ? '✅ Yes' : '❌ No'} |\n\n`;
if (tagExists || pypiExists) {
body += '### ⏭️ No Release\n\n';
if (tagExists && pypiExists) {
body += `Version \`${version}\` already exists on both GitHub and PyPI.\n\n`;
} else if (tagExists) {
body += `Git tag \`v${version}\` already exists.\n\n`;
} else {
body += `Version \`${version}\` already exists on PyPI.\n\n`;
}
body += '> 💡 **To create a new release**, update `version` in `pyproject.toml`\n';
} else {
body += '### 🚀 New Release\n\n';
body += 'When this PR is merged, the following will happen:\n\n';
body += `1. ✅ Create GitHub Release \`v${version}\`\n`;
body += `2. ✅ Publish to PyPI as \`late-sdk==${version}\`\n\n`;
body += '```bash\n';
body += `pip install late-sdk==${version}\n`;
body += '```\n';
}
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('📦 Release Preview')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
}