Skip to content

Commit 1bd33b0

Browse files
authored
Merge pull request #182 from visier/publish-sdk-fix
Fix not to skip action.
2 parents 3a0bfd6 + 90f5f94 commit 1bd33b0

1 file changed

Lines changed: 30 additions & 7 deletions

File tree

‎.github/workflows/publish-sdk.yml‎

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@ on:
44
push:
55
branches:
66
- 'release-**'
7+
workflow_dispatch:
8+
inputs:
9+
from_branch:
10+
description: 'Source branch to publish from'
11+
required: true
12+
default: 'release-main'
13+
type: string
14+
to_branch:
15+
description: 'Target branch to merge to'
16+
required: true
17+
default: 'github-action-test'
18+
type: string
19+
should_publish_to_pypi:
20+
description: 'Whether to publish package to PyPI'
21+
required: false
22+
default: false
23+
type: boolean
724

825
# Permissions to create PR, to write changes, to use PyPi auth
926
permissions:
@@ -13,9 +30,11 @@ permissions:
1330

1431
jobs:
1532
publish_package:
16-
if: startsWith(github.head_ref, 'release')
1733
name: Publish Python SDK to PyPI
1834
runs-on: ubuntu-latest
35+
env:
36+
SOURCE_BRANCH: ${{ github.event.inputs.from_branch || github.ref_name }}
37+
TARGET_BRANCH: ${{ github.event.inputs.to_branch || 'main' }}
1938
strategy:
2039
matrix:
2140
package_folder:
@@ -24,7 +43,7 @@ jobs:
2443
- name: Check out code
2544
uses: actions/checkout@v4
2645
with:
27-
ref: ${{ github.event.pull_request.head.ref }}
46+
ref: ${{ env.SOURCE_BRANCH }}
2847

2948
- name: Install dependencies
3049
run: |
@@ -37,15 +56,19 @@ jobs:
3756
python -m build --outdir ./dist
3857
3958
- name: Publish PyPi package
59+
if: github.event_name == 'workflow_dispatch' && github.event.inputs.should_publish_to_pypi == 'true' || github.event_name == 'push'
4060
uses: pypa/gh-action-pypi-publish@v1.12.4
4161
with:
4262
packages-dir: "src/${{ matrix.package_folder }}/dist"
4363

4464
create_and_merge_pr:
4565
needs: publish_package
46-
if: needs.publish_package.result == 'success'
66+
if: needs.publish_package.result == 'success' && (github.event_name == 'workflow_dispatch' && github.event.inputs.from_branch != github.event.inputs.to_branch)
4767
name: Merge PR
4868
runs-on: ubuntu-latest
69+
env:
70+
SOURCE_BRANCH: ${{ github.event.inputs.from_branch || github.ref_name }}
71+
TARGET_BRANCH: ${{ github.event.inputs.to_branch || 'main' }}
4972
steps:
5073
- name: Check out before merge
5174
uses: actions/checkout@v4
@@ -56,10 +79,10 @@ jobs:
5679
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5780
run: |
5881
pr_output=$(gh pr create \
59-
--title "Auto-generated SDK ${{ github.ref_name }}" \
60-
--body "This PR includes the autogenerated SDKs." \
61-
--head "${{ github.ref_name }}" \
62-
--base "${{ github.event_name == 'workflow_dispatch' }}")
82+
--title "Auto-generated SDK from ${{ env.SOURCE_BRANCH }}" \
83+
--body "This PR includes the autogenerated SDKs from branch ${{ env.SOURCE_BRANCH }}." \
84+
--head "${{ env.SOURCE_BRANCH }}" \
85+
--base "${{ env.TARGET_BRANCH }}")
6386
pr_number=$(echo "$pr_output" | grep -oE '[0-9]+$')
6487
echo "Pull Request #$pr_number created successfully."
6588
echo "pr_number=$pr_number" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)