Skip to content

[GHA] Add container build dependency to wait on wheels to be built #20

[GHA] Add container build dependency to wait on wheels to be built

[GHA] Add container build dependency to wait on wheels to be built #20

name: Build PyPi Wheel and Docker Container
on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- main
- 'release/[0-9]+.[0-9]+'
push:
branches:
- 'release/[0-9]+.[0-9]+'
- main
release:
types: [created, published]
schedule:
- cron: '0 0 * * *'
permissions:
id-token: write
contents: read
packages: write
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
# if not dev or release, will create a nightly build
# everything is pushed to internal unless created through a nightly scheduled cron job which creates the build or
# missing release tag workflow/needs to be added in
env:
INTERNAL: ${{ github.event_name != 'schedule' && github.event_name != 'release'}}
RELEASE: ${{ github.event_name =='release' || startsWith(github.base_ref, 'release/') }}
DEV: ${{ github.base_ref == 'main' && github.event_name == 'pull_request'}}
NAME: ${{ github.event.number }}
jobs:
build-wheel-and-push:
runs-on: ubuntu-20.04
outputs:
wheel: ${{ steps.push-wheel.outputs.wheel }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Login to s3
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.AWS_WEBIDENTITY_FOR_GITHUB_ACTIONS }}
aws-region: us-east-1
- name: Build PyPi Wheel
id: build-wheel
uses: neuralmagic/nm-actions/actions/pypi_build@main
with:
dev: $DEV
release: $RELEASE
name: $NAME
- name: Push to s3 bucket
id: push-wheel
uses: neuralmagic/nm-actions/actions/s3_push@main
with:
filename: dist/*.whl
internal: $INTERNAL
pull-wheel-and-test:
needs: build-wheel-and-push
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Login to s3
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.AWS_WEBIDENTITY_FOR_GITHUB_ACTIONS }}
aws-region: us-east-1
- name: Make directory for wheel
run: |
mkdir dist_s3
- name: Pull from s3
uses: neuralmagic/nm-actions/actions/s3_pull@main
with:
filename: ${{ needs.build-wheel-and-push.outputs.wheel }}
dst: dist_s3
- name: Install Wheel
run: |
pip install dist_s3/${{ needs.build-wheel-and-push.outputs.wheel }}[dev]
- name: Checkout code
uses: actions/checkout@v3
with:
sparse-checkout: 'tests'
sparse-checkout-cone-mode: false
- name: Remove non-test files and run tests
run: |
pip list
ls
make test
build-container-and-push:
needs: pull-wheel-and-test
runs-on: [aws-avx2-64G]
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
with:
buildkitd-flags: --debug
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y%m%d')"
- name: Get the current version
if: ${{ env.RELEASE == 'true' }}
id: version
run: echo "::set-output name=version::$(echo ${{ github.base_ref }} | cut -c 9-15)"
- name: Login to Github Packages
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Dev Docker Container
if: ${{ env.DEV == 'true' }}
uses: docker/build-push-action@v4
with:
context: ./docker/containers/docker_dev
build-args: |
BRANCH=${{github.head_ref}}
push: true
tags: ghcr.io/neuralmagic/sparseml-dev:${{ env.NAME }}
- name: Build Release Docker Container
if: ${{ env.RELEASE == 'true' }}
uses: docker/build-push-action@v4
with:
context: ./docker/containers/docker_release
build-args: |
VERSION=${{ steps.version.outputs.version }}
push: true
tags: ghcr.io/neuralmagic/test-sparseml:latest, ghcr.io/neuralmagic/test-sparseml:${{ steps.version.outputs.version }}
- name: Build Nightly Docker Container
if: ${{ env.DEV == 'false' && env.RELEASE == 'false'}}
uses: docker/build-push-action@v4
with:
context: ./docker/containers/docker_nightly
push: true
tags: ghcr.io/neuralmagic/test-sparseml-nightly:latest, ghcr.io/neuralmagic/test-sparseml-nightly:${{ steps.date.outputs.date }}