-
Notifications
You must be signed in to change notification settings - Fork 1
81 lines (81 loc) · 2.67 KB
/
publish_release.yml
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
name: Publish Release
on:
push:
branches:
- release_bfabric
- release_bfabric_scripts
- release_app_runner
workflow_dispatch:
inputs:
package:
description: 'Package to release'
type: choice
options:
- bfabric
- bfabric_scripts
- app_runner
default: bfabric
environment:
description: 'Target PyPI'
type: choice
options:
- test
- production
default: test
required: true
jobs:
publish:
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
# Step: Determine the package that is being built
- name: Set package variable
id: set-package
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "PACKAGE=${{ github.event.inputs.package }}" >> $GITHUB_ENV
else
# Extract package name from branch name by removing 'release_' prefix
BRANCH_NAME="${{ github.ref_name }}"
PACKAGE=${BRANCH_NAME#release_}
echo "PACKAGE=$PACKAGE" >> $GITHUB_ENV
fi
# Step: Set the PyPI repository URL based on environment
- name: Set PyPI repository URL
id: set-repo-url
run: |
if [ "${{ github.event.inputs.environment }}" == "production" ] || [ "${{ github.event_name }}" == "push" ]; then
echo "PYPI_REPOSITORY_URL=https://upload.pypi.org/legacy/" >> $GITHUB_ENV
else
echo "PYPI_REPOSITORY_URL=https://test.pypi.org/legacy/" >> $GITHUB_ENV
fi
- name: Debug variables
run: |
echo "Selected package: ${{ env.PACKAGE }}"
echo "Target PyPI repository: ${{ env.PYPI_REPOSITORY_URL }}"
# Step: Build the package
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install hatch
run: pip install hatch
- name: Build package
run: |
cd ${{ env.PACKAGE }}
hatch build
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: ${{ env.PYPI_REPOSITORY_URL }}
packages-dir: ${{ env.PACKAGE }}/dist
- name: Debug package info
run: |
echo "Built and published package: ${{ env.PACKAGE }}"
if [ "${{ env.PYPI_REPOSITORY_URL }}" == "https://pypi.org/legacy/" ]; then
echo "Check it at: https://pypi.org/project/${{ env.PACKAGE }}/"
else
echo "Check it at: https://test.pypi.org/project/${{ env.PACKAGE }}/"
fi