-
Notifications
You must be signed in to change notification settings - Fork 13
163 lines (134 loc) · 4.97 KB
/
ci.yaml
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
157
158
159
160
161
162
163
name: CI
on:
push:
pull_request_target:
types: [labeled]
env:
POETRY_VERSION: "1.5.1"
jobs:
prepare:
name: "Prepare"
runs-on: "ubuntu-22.04"
outputs:
sdk-test-credentials: "${{ steps.secrets.outputs.SDK_TEST_CREDENTIALS }}"
permissions:
id-token: "write"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: "Authenticate to Google Cloud"
id: "gcp-auth"
uses: "google-github-actions/auth@v1"
with:
token_format: "access_token"
workload_identity_provider: "${{ secrets.WORKLOAD_IDENTITY_PROVIDER }}"
service_account: "${{ secrets.SERVICE_ACCOUNT }}"
- name: "Get secrets"
id: "secrets"
uses: "google-github-actions/get-secretmanager-secrets@v1"
with:
secrets: |-
SDK_TEST_CREDENTIALS:projects/${{ secrets.GCP_PROJECT_NAME }}/secrets/SDK_TEST_CREDENTIALS
ci:
name: CI ${{ matrix.os }} / Python ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
if: github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'pr approved')
needs: "prepare"
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04]
python-version: ["3.8", "3.9", "3.10", "3.11"]
env:
PYTHONDONTWRITEBYTECODE: 1
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Setup poetry ${{ env.POETRY_VERSION }}
run: |
curl -sSl https://install.python-poetry.org | python - --version ${{ env.POETRY_VERSION }}
ln -s ${POETRY_HOME}/bin/poetry /usr/local/bin/poetry
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
- name: Set up poetry cache
uses: actions/cache@v3
with:
path: /home/runner/.cache/pypoetry/virtualenvs
key: venv-${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: venv-${{ matrix.os }}-${{ matrix.python-version }}-
- name: Install dependencies
run: |
poetry install --sync --no-root
- name: Lint
run: |
./bin/lint.sh
- name: Create config
env:
SDK_TEST_CREDENTIALS: ${{ needs.prepare.outputs.sdk-test-credentials }}
run: |
echo "USERNAME = \"$(jq -r .username <<< ${SDK_TEST_CREDENTIALS})\"" > tests/config.py
echo "PASSWORD = \"$(jq -r .password <<< ${SDK_TEST_CREDENTIALS})\"" >> tests/config.py
- name: Test
run: |
./bin/test.sh
release-package:
name: "Release package"
runs-on: "ubuntu-22.04"
needs: ["prepare", "ci"]
env:
PYTHON_VERSION: "3.11"
if: contains('refs/heads/master refs/heads/main', github.ref)
permissions:
contents: "write"
id-token: "write"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: "Setup python ${{ env.PYTHON_VERSION }}"
uses: "actions/setup-python@v4"
with:
python-version: "${{ env.PYTHON_VERSION }}"
cache: "pip"
- name: "Setup poetry ${{ env.POETRY_VERSION }}"
run: |
curl -sSL https://install.python-poetry.org | POETRY_HOME="$HOME/.poetry" python - --version ${{ env.POETRY_VERSION }} --force
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
- name: Should publish package
id: should-publish-package
run: |
npm install -g semver
ALL_GIT_TAGS=$(git tag)
ALL_RELEASES=$(semver ${ALL_GIT_TAGS})
LAST_RELEASE=$(semver ${ALL_GIT_TAGS} | tail -n1)
# Current version set in pyproject.toml file
CURRENT_VERSION=$(semver $(poetry version -s))
if [[ $ALL_RELEASES == *"${CURRENT_VERSION}"* ]]; then
echo "::warning::Package version in pyproject.toml not bumped, will not publish new package"
echo "publish=0" >> $GITHUB_OUTPUT
else
echo "::info::Package will be released. Last release version: ${LAST_RELEASE}, current version: ${CURRENT_VERSION}"
echo "publish=1" >> $GITHUB_OUTPUT
fi
- name: Get version
id: get-version
run: |
echo "version=$(poetry version -s)" >> $GITHUB_OUTPUT
if: steps.should-publish-package.outputs.publish == 1
- name: "Build final package"
run: |
poetry build
if: steps.should-publish-package.outputs.publish == 1
- name: "Publish package to PyPI"
uses: pypa/gh-action-pypi-publish@release/v1
if: steps.should-publish-package.outputs.publish == 1
- name: "Create release"
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.get-version.outputs.version }}
generate_release_notes: true
if: steps.should-publish-package.outputs.publish == 1