Skip to content

Commit f0f2ede

Browse files
authored
chore: set up release-please workflow and kokoro release script (#87)
* chore: add release-please workflow to repo * add kokoro config and scripts for releasing to PyPI * add setup.cfg
1 parent f8049ac commit f0f2ede

File tree

7 files changed

+154
-0
lines changed

7 files changed

+154
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
on:
2+
push:
3+
branches:
4+
- $default-branch
5+
name: release-please
6+
jobs:
7+
release-please:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: GoogleCloudPlatform/[email protected]
11+
with:
12+
token: ${{ secrets.GITHUB_TOKEN }}
13+
release-type: python
14+
package-name: cloud-sql-python-connector

.kokoro/populate-secrets.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
# Copyright 2021 Google LLC.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -eo pipefail
17+
18+
function now { date +"%Y-%m-%d %H:%M:%S" | tr -d '\n' ;}
19+
function msg { println "$*" >&2 ;}
20+
function println { printf '%s\n' "$(now) $*" ;}
21+
22+
23+
# Populates requested secrets set in SECRET_MANAGER_KEYS from service account:
24+
# kokoro-trampoline@cloud-devrel-kokoro-resources.iam.gserviceaccount.com
25+
SECRET_LOCATION="${KOKORO_GFILE_DIR}/secret_manager"
26+
msg "Creating folder on disk for secrets: ${SECRET_LOCATION}"
27+
mkdir -p ${SECRET_LOCATION}
28+
for key in $(echo ${SECRET_MANAGER_KEYS} | sed "s/,/ /g")
29+
do
30+
msg "Retrieving secret ${key}"
31+
docker run --entrypoint=gcloud \
32+
--volume=${KOKORO_GFILE_DIR}:${KOKORO_GFILE_DIR} \
33+
gcr.io/google.com/cloudsdktool/cloud-sdk \
34+
secrets versions access latest \
35+
--project cloud-devrel-kokoro-resources \
36+
--secret ${key} > \
37+
"${SECRET_LOCATION}/${key}"
38+
if [[ $? == 0 ]]; then
39+
msg "Secret written to ${SECRET_LOCATION}/${key}"
40+
else
41+
msg "Error retrieving secret ${key}"
42+
fi
43+
done

.kokoro/release.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
# Copyright 2021 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -eo pipefail
17+
18+
# Ensure that we have the latest versions of Twine, Wheel, and Setuptools.
19+
python3 -m pip install --upgrade twine wheel setuptools
20+
21+
# Disable buffering, so that the logs stream through.
22+
export PYTHONUNBUFFERED=1
23+
24+
# Move into the package, build the distribution and upload.
25+
TWINE_PASSWORD=$(cat "${KOKORO_GFILE_DIR}/secret_manager/google-cloud-pypi-token")
26+
cd github/cloud-sql-python-connector
27+
python3 setup.py sdist bdist_wheel
28+
twine upload --username __token__ --password "${TWINE_PASSWORD}" dist/*

.kokoro/release/common.cfg

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# Format: //devtools/kokoro/config/proto/build.proto
15+
16+
# Build logs will be here
17+
action {
18+
define_artifacts {
19+
regex: "**/*sponge_log.xml"
20+
}
21+
}
22+
23+
# Download trampoline resources.
24+
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
25+
26+
# Use the trampoline script to run in docker.
27+
build_file: "cloud-sql-python-connector/.kokoro/trampoline.sh"
28+
29+
# Configure the docker image for kokoro-trampoline.
30+
env_vars: {
31+
key: "TRAMPOLINE_IMAGE"
32+
value: "python:3.8"
33+
}
34+
env_vars: {
35+
key: "TRAMPOLINE_BUILD_FILE"
36+
value: "github/cloud-sql-python-connector/.kokoro/release.sh"
37+
}
38+
39+
# Tokens needed to report release status back to GitHub
40+
env_vars: {
41+
key: "SECRET_MANAGER_KEYS"
42+
value: "google-cloud-pypi-token"
43+
}

.kokoro/release/release.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto

.kokoro/trampoline.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,14 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
# Always run the cleanup script, regardless of the success of bouncing into
17+
# the container.
18+
function cleanup() {
19+
chmod +x ${KOKORO_GFILE_DIR}/trampoline_cleanup.sh
20+
${KOKORO_GFILE_DIR}/trampoline_cleanup.sh
21+
echo "cleanup";
22+
}
23+
trap cleanup EXIT
24+
25+
$(dirname $0)/populate-secrets.sh # Secret Manager secrets.
1626
python3 "${KOKORO_GFILE_DIR}/trampoline_v1.py"

setup.cfg

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
[bdist_wheel]
15+
universal = 1

0 commit comments

Comments
 (0)