-
Notifications
You must be signed in to change notification settings - Fork 4
131 lines (110 loc) · 3.81 KB
/
release.yml
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
# This workflow tests and releases a new version of the package before publishing it to PyPi.
name: Release
# Only trigger when a pull request into main branch is merged.
on:
pull_request:
types: [closed]
branches:
- main
workflow_dispatch:
inputs:
ref:
description: "Branch or commit SHA to tag"
type: string
required: true
tag:
description: "Tag for release"
type: string
required: true
jobs:
run-tests:
if: "${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true }}"
runs-on: ${{ matrix.os }}
env:
USING_COVERAGE: "3.10"
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
permissions:
id-token: write
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install Poetry
uses: snok/[email protected]
- name: Check pyproject.toml file
run: poetry check
- name: Install tox
run: pip install tox
- name: Authenticate with Google Cloud
id: auth
uses: google-github-actions/[email protected]
with:
# NOTE: If setting create_credentials_file=true, .dockerignore file must include `gha-creds-*.json` to avoid baking these credentials into build
create_credentials_file: true
workload_identity_provider: "projects/437801218871/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider"
service_account: "[email protected]"
- name: Run tests
env:
TEST_PROJECT_NAME: ${{ secrets.TEST_PROJECT_NAME }}
GOOGLE_CLOUD_PROJECT: ${{ secrets.TEST_PROJECT_NAME }}
run: tox -vv -e py
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
files: coverage.xml
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
release:
runs-on: ubuntu-latest
needs: run-tests
steps:
- name: Checkout Repository
if: ${{ github.event_name != 'workflow_dispatch' }}
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Install Poetry
if: ${{ github.event_name != 'workflow_dispatch' }}
uses: snok/[email protected]
- name: Check pyproject.toml file
if: ${{ github.event_name != 'workflow_dispatch' }}
run: poetry check
- name: Get package version
id: get-package-version
if: ${{ github.event_name != 'workflow_dispatch' }}
run: echo "package_version=$(poetry version -s)" >> $GITHUB_OUTPUT
- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, no need to create your own.
with:
commitish: ${{ inputs.ref }}
tag_name: ${{ inputs.tag || steps.get-package-version.outputs.package_version }}
release_name: ${{ github.event.pull_request.title }}
body: ${{ github.event.pull_request.body }}
draft: false
prerelease: false
publish:
needs: release
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.tag }}
- name: Install Poetry
uses: snok/[email protected]
- name: Build a binary wheel and a source tarball
run: poetry build
- name: Publish package distributions to PyPI
uses: pypa/[email protected]