@@ -3,33 +3,83 @@ name: Publish to PyPI and GitHub release
33on :
44 push :
55 tags :
6- - ' v*'
6+ - ' v*'
7+ workflow_dispatch :
8+ inputs :
9+ ref :
10+ description : ' Git ref (branch, tag, or SHA) to build from'
11+ required : true
12+ default : ' main'
13+ type : string
14+
15+ # Least-privilege defaults for all jobs (override per-job if needed)
16+ permissions :
17+ contents : write # to create releases and read code
18+ packages : write # to push container images to ghcr.io
19+ id-token : write # for PyPI OIDC publish
720
821jobs :
922 python-package :
1023 runs-on : ubuntu-latest
11- permissions :
12- id-token : write
24+
1325 steps :
26+ - name : Select ref
27+ id : select-ref
28+ run : |
29+ if [ -n "${{ github.event.inputs.ref }}" ]; then
30+ echo "ref=${{ github.event.inputs.ref }}" >> $GITHUB_OUTPUT
31+ else
32+ # Fallback to the event ref (e.g. refs/tags/v1.2.3 on tag pushes)
33+ echo "ref=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
34+ fi
35+
1436 - uses : actions/checkout@v4
37+ with :
38+ # Checkout the chosen ref for manual runs; for tag-push runs this will be that tag
39+ ref : ${{ steps.select-ref.outputs.ref }}
40+
41+ - name : Derive version
42+ id : version
43+ shell : bash
44+ run : |
45+ # If the ref looks like a release tag (v*), use it as version (strip refs/tags/ if present)
46+ REF="${{ steps.select-ref.outputs.ref }}"
47+ if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
48+ VER="${GITHUB_REF#refs/tags/}"
49+ elif [[ "$REF" == refs/tags/v* ]]; then
50+ VER="${REF#refs/tags/}"
51+ elif [[ "$REF" == v* ]]; then
52+ VER="$REF"
53+ else
54+ # Fallback for non-tag manual runs
55+ VER="manual-${{ github.run_number }}"
56+ fi
57+ echo "version=$VER" >> $GITHUB_OUTPUT
58+ echo "Resolved version: $VER"
59+
1560 - name : Set up Python
1661 uses : actions/setup-python@v5
1762 with :
1863 python-version : ' 3.11'
64+
1965 - name : Install dependencies
2066 run : |
2167 python -m pip install --upgrade pip
2268 pip install build flake8
69+
2370 - name : Check for syntax errors
2471 run : |
2572 flake8 ./deeplc --count --select=E9,F63,F7,F82 --show-source --statistics
73+
2674 - name : Build package
2775 run : |
2876 python -m build . --sdist --wheel
77+
2978 - name : Publish to PyPI
3079 uses : pypa/gh-action-pypi-publish@release/v1
3180 with :
3281 skip-existing : true
82+
3383 - name : Upload compiled wheels
3484 uses : actions/upload-artifact@v4
3585 with :
4191 needs : python-package
4292 steps :
4393 - uses : actions/checkout@v4
94+ with :
95+ # Match the same ref used for building the Python package
96+ ref : ${{ needs.python-package.outputs.ref || github.ref }}
97+ # If you want to avoid recomputing the ref/version here, you can
98+ # alternatively repeat the "Select ref" + "Derive version" steps as above
4499 - uses : actions/setup-python@v5
45100 with :
46101 python-version : ' 3.11'
@@ -56,8 +111,24 @@ jobs:
56111 run : pyinstaller ./deeplc_pyinstaller.spec --clean --noconfirm
57112 - name : Test built DeepLC exe
58113 run : dist/deeplc/deeplc.exe --ignore-gooey --help
114+ - name : Derive version (Windows)
115+ id : version
116+ shell : bash
117+ run : |
118+ REF="${{ github.event.inputs.ref }}"
119+ if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
120+ VER="${GITHUB_REF#refs/tags/}"
121+ elif [[ "$REF" == refs/tags/v* ]]; then
122+ VER="${REF#refs/tags/}"
123+ elif [[ "$REF" == v* ]]; then
124+ VER="$REF"
125+ else
126+ VER="manual-${{ github.run_number }}"
127+ fi
128+ echo "version=$VER" >> $GITHUB_OUTPUT
129+ echo "Resolved version: $VER"
59130 - name : Run Inno Setup
60- run : ISCC.exe ./deeplc_innosetup.iss /DAppVersion=${{ github.ref_name }}
131+ run : ISCC.exe ./deeplc_innosetup.iss /DAppVersion=${{ steps.version.outputs.version }}
61132 - name : Upload installer
62133 uses : actions/upload-artifact@v4
63134 with :
@@ -67,19 +138,41 @@ jobs:
67138 git-release :
68139 runs-on : ubuntu-latest
69140 needs : [python-package, windows-installer]
141+ # Only create a GitHub Release when the ref is a v* tag (either push or manual)
142+ if : startsWith(github.ref, 'refs/tags/v') || startsWith(github.event.inputs.ref, 'v')
70143 steps :
71144 - uses : actions/checkout@v4
72- - name : Download installer
145+
146+ - name : Resolve version/tag
147+ id : version
148+ shell : bash
149+ run : |
150+ if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
151+ VER="${GITHUB_REF#refs/tags/}"
152+ elif [[ "${{ github.event.inputs.ref }}" == v* ]]; then
153+ VER="${{ github.event.inputs.ref }}"
154+ else
155+ echo "This job should only run for v* tags."
156+ exit 1
157+ fi
158+ echo "version=$VER" >> $GITHUB_OUTPUT
159+ echo "Resolved version: $VER"
160+
161+ - name : Download artifacts
73162 uses : actions/download-artifact@v4
74163 with :
75164 path : dist
165+
76166 - name : Create GitHub Release
167+ # The docker action infers the tag from GITHUB_REF; set it explicitly for manual runs.
77168 uses : docker://antonyurchenko/git-release:v6
78169 env :
79170 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
80171 DRAFT_RELEASE : " false"
81172 PRE_RELEASE : " false"
82173 CHANGELOG_FILE : " CHANGELOG.md"
174+ # Provide a synthetic tag ref for manual runs with input v*
175+ GITHUB_REF : refs/tags/${{ steps.version.outputs.version }}
83176 with :
84177 args : |
85178 dist/**/*.exe
0 commit comments