Skip to content

Commit

Permalink
Prototype: Add GitHub actions to test the project and package on each…
Browse files Browse the repository at this point in the history
… pull request.

PiperOrigin-RevId: 640549692
  • Loading branch information
michaelreneer authored and copybara-github committed Jun 15, 2024
1 parent 9850438 commit 6179897
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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: Tests

on: # yamllint disable-line rule:truthy

# presubmit
# pull_request:
# branches:
# - 'cl/[0-9]+'
# push:

# manual
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:

test_project:
name: Project
uses: ./.github/workflows/test_project.yaml
secrets: inherit

test_package:
name: Package
uses: ./.github/workflows/test_package.yaml
secrets: inherit
122 changes: 122 additions & 0 deletions .github/workflows/test_package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# 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: Test Package

on: # yamllint disable-line rule:truthy

# presubmit
# workflow_call:
push:

# manual
workflow_dispatch:

# concurrency:
# group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
# cancel-in-progress: true

jobs:

build-package:
name: Build Package
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__)"
81 changes: 81 additions & 0 deletions .github/workflows/test_project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# 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: Test Project

on: # yamllint disable-line rule:truthy

# presubmit
# workflow_call:
push:

# manual
workflow_dispatch:

# concurrency:
# group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
# cancel-in-progress: true

jobs:

test-project:
name: Linux PY ${{ matrix.python-version }}
runs-on: ubuntu-latest
timeout-minutes: 160
strategy:
fail-fast: false
matrix:
python-version: ["3.11"] # , "3.9", "3.10"
steps:

- name: Checkout repository
uses: actions/[email protected]

- 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: ${{ matrix.python-version }}
cache: "pip"

- name: Install Python dependencies
run: |
pip install --upgrade "pip"
pip install --upgrade --requirement "requirements.txt"
- name: Test build
run: |
pip install --upgrade "numpy~=1.25"
python_version="${{ matrix.python-version }}"
python_version="${python_version//.}"
bazelisk test //tensorflow_federated/... \
--build_tag_filters="-nokokoro,-nopresubmit,-requires-gpu-nvidia" \
--test_size_filters="small,medium,large" \
--test_timeout_filters="short,moderate,long" \
--test_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 }}-py${python_version}"

0 comments on commit 6179897

Please sign in to comment.