Skip to content

Commit d8f45d4

Browse files
committed
feat(ci): support altering package names before publication (useful in rare occasions)
1 parent 3ad3541 commit d8f45d4

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

.github/workflows/release.yml

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ on:
2121

2222
# MUSTHAVE: Trusted publisher access for both repos.
2323
# NOTE: according to docs, 'test' repo accounts are ephemeral and can be wiped at any time
24+
# NOTE: 'test' accs are not that ephmeperal -- losing access to sandbox account (2FA issue) effectively locked us out of project; good test for workarounds though
25+
# NOTE: as a part of regaining-control scenario we may use distinct project names in pyroject.toml (e.g. appmap-dev, appmap-ng)
2426
env:
2527
DRY_RUN: ${{ github.event.inputs.dry_run || 'false' }}
26-
pypi_main_repo: https://upload.pypi.org/legacy/
27-
pypi_test_repo: https://test.pypi.org/legacy/
28+
pypi_project: appmap
29+
testpypi_project: appmap-dev # workaround for lost-access scenario
30+
2831

2932
jobs:
3033

@@ -41,17 +44,19 @@ jobs:
4144
- uses: ./.github/actions/setup # poetry
4245
- id: semantic-release # branch policies defined in .releaserc
4346
env:
44-
GIT_AUTHOR_NAME: appland-release
45-
GIT_AUTHOR_EMAIL: release@app.land
46-
GIT_COMMITTER_NAME: appland-release
47-
GIT_COMMITTER_EMAIL: release@app.land
48-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
GIT_AUTHOR_NAME: appland-release
48+
GIT_AUTHOR_EMAIL: release@app.land
49+
GIT_COMMITTER_NAME: appland-release
50+
GIT_COMMITTER_EMAIL: release@app.land
51+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
ALT_PYPI_PROJECT_NAME: ${{ github.ref_name=='master' && env.pypi_project || env.testpypi_project }}
4953
run: |
5054
if [ "$DRY_RUN" = "true" ]; then
5155
semantic-release --dry-run
5256
else
5357
semantic-release
5458
fi
59+
5560
- name: Upload wheel
5661
if: env.DRY_RUN != 'true'
5762
uses: actions/upload-artifact@v4
@@ -84,6 +89,7 @@ jobs:
8489
env:
8590
SMOKETEST_DOCKER_IMAGE: python:3.12-slim
8691

92+
# as a workaround to ownership issues (lost access to project)
8793
pypi:
8894
name: upload release to PyPI
8995
needs: ['release','smoketest']
@@ -95,7 +101,19 @@ jobs:
95101
steps:
96102
- uses: actions/checkout@v5
97103
- uses: ./.github/actions/refetch-artifacts
98-
- name: Publish package distributions to PyPI
104+
105+
- name: Publish to PyPI
106+
if: github.ref_name == 'master'
107+
uses: pypa/gh-action-pypi-publish@release/v1
108+
environment:
109+
name: pypi
110+
url: https://pypi.org/project/${{ env.pypi_project }}
111+
112+
- name: Publish to TestPyPI
113+
if: github.ref_name != 'master'
99114
uses: pypa/gh-action-pypi-publish@release/v1
115+
environment:
116+
name: testpypi
117+
url: https://test.pypi.org/project/${{ env.testpypi_project_name }}
100118
with:
101-
repository-url: ${{ github.ref_name == 'master' && env.pypi_main_repo || env.pypi_test_repo }}
119+
repository-url: https://test.pypi.org/uploads/legacy

.releaserc.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ plugins:
3939
- CHANGELOG.md
4040
- pyproject.toml
4141
- - '@semantic-release/exec'
42-
- prepareCmd: poetry build
42+
- prepareCmd: |
43+
# alt name patch is done for publication only, therefore after canonical version of pyproject.toml is commited
44+
if [ -n "$ALT_PYPI_PROJECT_NAME" ]; then
45+
sed -i "s/^name = \".*\"/name = \"$ALT_PYPI_PROJECT_NAME\"/" pyproject.toml
46+
fi
47+
poetry build
4348
- - '@semantic-release/github'
4449
- assets:
4550
- dist/*.whl

0 commit comments

Comments
 (0)