1
+ name : PR Pre-release
2
+
3
+ on :
4
+ pull_request :
5
+ types : [opened, synchronize, reopened]
6
+
7
+ permissions :
8
+ contents : write
9
+ pull-requests : write
10
+ issues : write
11
+ packages : write
12
+ id-token : write
13
+
14
+ jobs :
15
+ pre-release :
16
+ runs-on : ubuntu-latest
17
+ steps :
18
+ - name : Checkout repository
19
+ uses : actions/checkout@v4
20
+ with :
21
+ fetch-depth : 0
22
+ ref : ${{ github.event.pull_request.head.ref }}
23
+ token : ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
24
+
25
+ - name : Set up Python
26
+ uses : actions/setup-python@v4
27
+ with :
28
+ python-version : " 3.11"
29
+ cache : ' pip'
30
+
31
+ - name : Install dependencies
32
+ run : |
33
+ python -m pip install --upgrade pip
34
+ pip install python-semantic-release
35
+
36
+ - name : Configure git
37
+ run : |
38
+ git config --global user.name "github-actions[bot]"
39
+ git config --global user.email "github-actions[bot]@users.noreply.github.com"
40
+
41
+ - name : Generate RC version
42
+ id : version
43
+ env :
44
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
45
+ run : |
46
+ # Get the current version
47
+ CURRENT_VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
48
+
49
+ # Generate RC version based on PR number
50
+ RC_VERSION="${CURRENT_VERSION}-rc.${{ github.event.pull_request.number }}"
51
+ echo "RC_VERSION=${RC_VERSION}" >> $GITHUB_OUTPUT
52
+
53
+ # Update version in files
54
+ sed -i "s/version = \"${CURRENT_VERSION}\"/version = \"${RC_VERSION}\"/" pyproject.toml
55
+ sed -i "s/__version__ = \"${CURRENT_VERSION}\"/__version__ = \"${RC_VERSION}\"/" src/__init__.py
56
+
57
+ # Create pre-release tag (delete if exists)
58
+ git add pyproject.toml src/__init__.py
59
+ git commit -m "chore: bump version to ${RC_VERSION} [skip ci]" || echo "No changes to commit"
60
+
61
+ # Delete existing tag if it exists (locally and remotely)
62
+ git tag -d "v${RC_VERSION}" 2>/dev/null || true
63
+ git push --delete origin "v${RC_VERSION}" 2>/dev/null || true
64
+
65
+ # Create new tag
66
+ git tag -a "v${RC_VERSION}" -m "Pre-release version ${RC_VERSION}"
67
+
68
+ - name : Push tag to trigger Docker build
69
+ run : |
70
+ git push origin "v${{ steps.version.outputs.RC_VERSION }}"
71
+
72
+ - name : Set up Docker Buildx
73
+ uses : docker/setup-buildx-action@v3
74
+
75
+ - name : Log in to Container Registry
76
+ uses : docker/login-action@v3
77
+ with :
78
+ registry : ghcr.io
79
+ username : ${{ github.actor }}
80
+ password : ${{ secrets.GITHUB_TOKEN }}
81
+
82
+ - name : Build and push Docker image
83
+ uses : docker/build-push-action@v5
84
+ with :
85
+ context : .
86
+ platforms : linux/amd64,linux/arm64
87
+ push : true
88
+ tags : ghcr.io/${{ github.repository_owner }}/mcp-oauth-gateway:v${{ steps.version.outputs.RC_VERSION }}
89
+ cache-from : type=gha
90
+ cache-to : type=gha,mode=max
91
+
92
+ - name : Create GitHub pre-release
93
+ env :
94
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
95
+ run : |
96
+ gh release create "v${{ steps.version.outputs.RC_VERSION }}" \
97
+ --title "Pre-release v${{ steps.version.outputs.RC_VERSION }}" \
98
+ --notes "Pre-release version for PR #${{ github.event.pull_request.number }}" \
99
+ --prerelease \
100
+ --target ${{ github.event.pull_request.head.sha }}
101
+
102
+ - name : Comment on PR
103
+ uses : actions/github-script@v7
104
+ with :
105
+ script : |
106
+ const rcVersion = '${{ steps.version.outputs.RC_VERSION }}';
107
+ const comment = `🚀 **Pre-release version created: \`v${rcVersion}\`**
108
+
109
+ This pre-release version can be used for testing this PR.
110
+
111
+ **Docker image**: \`ghcr.io/${{ github.repository }}:v${rcVersion}\``;
112
+
113
+ github.rest.issues.createComment({
114
+ issue_number: context.issue.number,
115
+ owner: context.repo.owner,
116
+ repo: context.repo.repo,
117
+ body: comment
118
+ });
0 commit comments