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 26, 2024
1 parent e8153c1 commit 78c6370
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 91 deletions.
97 changes: 6 additions & 91 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,102 +91,17 @@ jobs:
--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__)"
needs: [publish-release]
uses: ./.github/workflows/test_package.yaml
with:
ref: ${{ needs.publish-release.outputs.release-tag }}
secrets: inherit

publish-package:
name: Publish Package
needs: [build-package, test-package]
needs: [test-package]
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
Expand Down
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
127 changes: 127 additions & 0 deletions .github/workflows/test_package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# 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:
inputs:
ref:
description: "The branch, tag or SHA to checkout."
default: ''
required: false
type: string

# 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: ${{ inputs.ref }}

- 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: ${{ inputs.ref }}

- 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__)"
83 changes: 83 additions & 0 deletions .github/workflows/test_project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# 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:

# manual
workflow_dispatch:

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

jobs:

test-project:
name: Linux ${{ matrix.device-type }} PY ${{ matrix.python-version }}
runs-on: ubuntu-latest
timeout-minutes: 160
strategy:
fail-fast: false
matrix:
device-type: ["CPU"]
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"
device_type="${{ matrix.device-type }}"
device_type="${device_type,,}"
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 78c6370

Please sign in to comment.