This repository was archived by the owner on Aug 25, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_poetry_semantic_release.yaml
More file actions
156 lines (140 loc) · 4.64 KB
/
Copy pathpython_poetry_semantic_release.yaml
File metadata and controls
156 lines (140 loc) · 4.64 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
on:
workflow_call:
secrets:
GH_TOKEN:
required: true
inputs:
workdir:
description: "Working directory."
type: string
required: false
default: "."
release_suffix:
description: "Suffix (a.k.a build metadata) appended by semantic-release to the version number."
required: false
type: string
default: ""
release_vcs:
description: "If true, a Github release will be published."
required: false
type: boolean
default: false
release_commit:
description: "If true, the release commit will be created."
required: false
type: boolean
default: false
release_tag:
description: "If true, the release tag will be created."
required: false
type: boolean
default: false
release_changelog:
description: "If true, the changelog will be updated."
required: false
type: boolean
default: false
release_build:
description: "If true, the package will be built."
required: false
type: boolean
default: false
publish:
description: "If true, the package will be published to the target repository."
required: false
type: boolean
default: false
publish_repository:
description: "Poetry repository to publish to. The target repository should be configured poetry.toml."
required: false
type: string
publish_project_id:
description: "GC project ID."
required: false
type: string
publish_project_number:
description: "GC project number, not the project ID."
required: false
type: string
python-version:
description: "Python version to use for publishing."
type: string
required: false
default: "3.10"
outputs:
version:
value: ${{ jobs.release.outputs.version }}
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
jobs:
release:
name: Semantic Release
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.workdir }}
permissions:
contents: "write"
id-token: "write"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0
- name: Setup Poetry
run: pipx install poetry
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
cache: "poetry"
- name: Poetry install
run: poetry install
- name: Poetry key-ring
run: poetry self add keyrings.google-artifactregistry-auth
- name: Semantic Release Setup
run: |
git config --global user.name "Semantic Release"
git config --global user.email "github@digitlcloud.com"
- name: Set version output
id: set_version
run: |
VERSION=$(poetry run semantic-release version --build-metadata ${{ inputs.release_suffix }} --print)
echo "version=$VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Python Semantic Release
run: |
params=()
if [[ ${{ inputs.release_vcs }} == false ]]; then
params+=("--no-vcs-release")
fi
if [[ ${{ inputs.release_commit }} == false ]]; then
params+=("--no-commit")
fi
if [[ ${{ inputs.release_tag }} == false ]]; then
params+=("--no-tag")
fi
if [[ ${{ inputs.release_changelog }} == false ]]; then
params+=("--no-changelog")
fi
if [[ ${{ inputs.release_build }} == false ]]; then
params+=("--skip-build")
fi
poetry run semantic-release -v version \
--build-metadata ${{ inputs.release_suffix }} \
"${params[@]}"
- name: Authenticate to Google Cloud
if: inputs.publish == true
uses: google-github-actions/auth@v2
with:
workload_identity_provider: "projects/${{ inputs.publish_project_number }}/locations/global/workloadIdentityPools/github-actions/providers/github-actions"
service_account: "github-actions@${{ inputs.publish_project_id }}.iam.gserviceaccount.com"
- name: Set up Cloud SDK
if: inputs.publish == true
uses: "google-github-actions/setup-gcloud@v2"
- name: Poetry publish
if: inputs.publish == true
run: poetry publish --build -r ${{ inputs.publish_repository }} --skip-existing
outputs:
version: ${{ steps.set_version.outputs.version }}