-
Notifications
You must be signed in to change notification settings - Fork 582
203 lines (174 loc) · 5.92 KB
/
publish.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Publish
on: # yamllint disable-line rule:truthy
# postsubmit
push:
branches:
- main
paths:
- 'tensorflow_federated/version.py'
# manual
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
publish-release:
name: Publish Release
# Only if:
# * Repository is not a fork.
# * Branch is `main` (for workflow_dispatch trigger).
if: |
github.repository == 'google-parfait/tensorflow-federated'
&& github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: write # Required to create a release.
outputs:
release-tag: v${{ env.version }}
steps:
- name: Checkout repository
uses: actions/[email protected]
- name: Get the latest version
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
latest_version="$(gh release view \
--json "tagName" \
--jq ".tagName" \
| sed "s/^v//")"
echo "latest_version=${latest_version}" >> $GITHUB_ENV
- name: Get the version
run: |
version="$(sed --quiet \
"s/^__version__ = '\(.*\)'$/\1/p" \
"tensorflow_federated/version.py")"
echo "version=${version}" >> $GITHUB_ENV
- name: Get the description
run: |
description="$(sed --quiet \
"/^## Release ${{ env.version }}$/,/^## Release /p" \
"RELEASE.md" \
| head --lines=-1 \
| sed "s/^#//")"
{
echo "description<<EOF"
echo "${description}"
echo "EOF"
} >> "$GITHUB_ENV"
- name: Publish release
if: ${{ env.latest_version != env.version }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "v${{ env.version }}" \
--target="${{ github.sha }}" \
--title="TensorFlow Federated ${{ env.version }}" \
--notes='${{ env.description }}'
build-package:
name: Build Package
needs: [publish-release]
runs-on: ubuntu-20.04
timeout-minutes: 60
steps:
- name: Checkout repository
uses: actions/[email protected]
with:
ref: ${{ needs.publish-release.outputs.release-tag }}
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/[email protected]
with:
credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }}
create_credentials_file: true
- name: Set up bazel repository cache
uses: actions/[email protected]
with:
path: "~/.cache/bazel/"
key: ${{ runner.os }}-bazel-${{ hashFiles('.bazelversion', '.bazelrc', 'WORKSPACE') }}
restore-keys: ${{ runner.os }}-bazel-
- name: Set up Python
uses: actions/[email protected]
with:
python-version: "3.11"
cache: "pip"
- name: Install Python dependencies
run: |
pip install --upgrade "pip"
- name: Build Python package
run: |
pip install --upgrade "numpy~=1.25"
bazelisk run //tools/python_package:build_python_package \
--build_tag_filters="-nokokoro,-nopresubmit,-requires-gpu-nvidia" \
--google_credentials="${{ steps.auth.outputs.credentials_file_path }}" \
--remote_cache="https://storage.googleapis.com/tensorflow-federated-bazel-cache/${{ github.job }}" \
-- \
--output_dir="${{ github.workspace }}/dist/"
- name: Upload Python package
uses: actions/[email protected]
with:
name: python-package-distributions
path: dist/*.whl
test-package:
name: Test Package
needs: [build-package]
runs-on: ubuntu-20.04
timeout-minutes: 5
steps:
- name: Checkout repository
uses: actions/[email protected]
with:
ref: ${{ needs.publish-release.outputs.release-tag }}
- name: Download Python package
uses: actions/[email protected]
with:
name: python-package-distributions
path: dist/
- name: Set up Python
uses: actions/[email protected]
with:
python-version: "3.11"
cache: "pip"
- name: Install Python dependencies
run: |
pip install --upgrade "pip"
- name: Test Python package
run: |
package="$(ls "${{ github.workspace }}/dist/"*".whl" | head -n1)"
actual_size="$(du -b "${package}" | cut -f1)"
maximum_size=80000000 # 80 MiB
if [[ "${actual_size}" -ge "${maximum_size}" ]]; then
echo "error: expected '${package}' to be less than '${maximum_size}' bytes, it was '${actual_size}' bytes" 1>&2
exit 1
fi
pip install --upgrade "${package}"
python -I -c "import tensorflow_federated as tff; print(tff.federated_computation(lambda: 'Hello World')())"
python -I -c "import tensorflow_federated as tff; print(tff.__version__)"
publish-package:
name: Publish Package
needs: [build-package, test-package]
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
id-token: write # Required for trusted publishing.
steps:
- name: Download Python package
uses: actions/[email protected]
with:
name: python-package-distributions
path: dist/
- name: Publish Python package
uses: pypa/[email protected]