Skip to content

Commit

Permalink
ci: updated workflows with separate docker steps
Browse files Browse the repository at this point in the history
  • Loading branch information
nishaq503 committed Jan 30, 2024
1 parent dcc2924 commit fba2ba5
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 147 deletions.
59 changes: 0 additions & 59 deletions .github/workflows/docker.yml

This file was deleted.

7 changes: 6 additions & 1 deletion .github/workflows/package-filter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ on:
required: true
default: 0
type: number
ignore-missing-dev:
description: "If true, the action will ignore packages that do not have a dev version. Otherwise, the action will fail if any package does not have a dev version."
required: true
default: false
type: boolean
outputs:
matrix:
description: "The directories containing the updated packages"
Expand Down Expand Up @@ -79,7 +84,7 @@ jobs:
done
# Check that the version is a dev version
if [[ "$(cat ${pkg_dir}/VERSION)" != *"dev"* ]]
if [[ "$(cat ${pkg_dir}/VERSION)" != *"dev"* ]] || [[ ${{ inputs.ignore-missing-dev }} ]]
then
echo "::error::${pkg_dir} does not have a dev version" && exit 1
fi
Expand Down
65 changes: 43 additions & 22 deletions .github/workflows/package-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ on:
required: true
default: 1
type: number
ignore-missing-dev:
description: "If true, the action will ignore packages that do not have a dev version. Otherwise, the action will fail if any package does not have a dev version."
required: true
default: true
type: boolean
repo_name:
description: 'Name of the base repository. The user can ignore this input if the action is triggered from the base repository.'
required: true
Expand Down Expand Up @@ -41,19 +46,20 @@ permissions:

jobs:
package-filter:
name: Filter for updated package
name: Filter for updated packages
if: github.repository == 'polusai/${{ github.event.inputs.repo_name }}'
uses: ./.github/workflows/package-filter.yml
with:
num-commits: ${{ fromJson(github.event.inputs.num-commits) }}
ignore-missing-dev: ${{ fromJson(github.event.inputs.ignore-missing-dev) }}

package-release:
name: Release "${{ matrix.package_name }}"
name: Release | ${{ matrix.package_name }}
if: github.repository == 'polusai/${{ github.event.inputs.repo_name }}'
needs: package-filter
strategy:
fail-fast: false
matrix: ${{fromJson(needs.package-filter.outputs.matrix)}}
matrix: ${{ fromJson(needs.package-filter.outputs.matrix) }}
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -62,51 +68,66 @@ jobs:
fetch-depth: 0
ref: ${{ github.event.inputs.branch }}
persist-credentials: false
- name: Generate a token
- name: Token | Generate
id: generate_token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Use the token
- name: Token | Use the token
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
run: |
gh api octocat
- name: Set up Python
- name: Python | Setup
uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Install bump2version
- name: Python | Install bump2version
run: |
python -m pip install --upgrade pip
pip install bump2version
- name: Bump Version
- name: Python | Bump Version Release
run: |
cd "${{ matrix.package_dir }}"
bump2version release --no-commit
- name: Commit all changed files
- name: Git | Commit
env:
CI_COMMIT_AUTHOR: polusai-auth-helper[bot]
CI_COMMIT_EMAIL: ${{ secrets.APP_ID }}+polusai-auth-helper[bot]@users.noreply.github.com
run: |
git config --global user.name "${{ env.CI_COMMIT_AUTHOR }}"
git config --global user.email "${{ env.CI_COMMIT_EMAIL }}"
git commit -a -m "build: Bumped release version for ${{ matrix.package_name }}"
- name: Push changes
- name: Git | Push
uses: ad-m/github-push-action@master
with:
force: true
github_token: ${{ steps.generate_token.outputs.token }}

docker:
name: Build Docker images
if: github.repository == 'polusai/${{ github.event.inputs.repo_name }}'
needs: [package-filter, package-release]
uses: ./.github/workflows/docker.yml
with:
matrix: ${{ needs.package-filter.outputs.matrix }}
push: true
secrets:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
- name: Docker | Tag
id: docker_tag
run: |
package_dir="${{ matrix.package_dir }}"
cp .gitignore ${package_dir}/.dockerignore
version=$(cat ${package_dir}/VERSION)
tag=polusai/${{ matrix.package_name }}:${version}
echo "tag=${tag}" >> $GITHUB_OUTPUT
- name: Docker | Setup Buildx
uses: docker/setup-buildx-action@v3
- name: Docker | Login DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Docker | Check if Image exists
run: |
tag=${{ steps.docker_tag.outputs.tag }}
docker pull ${tag} > /dev/null \
&& $(echo "::error::${tag} already exists on DockerHub" && exit 1) \
|| echo "success"
- name: Docekr | Push Image
uses: docker/build-push-action@v5
with:
context: "{{defaultContext}}:${{ matrix.package_dir }}"
push: true
tags: ${{ steps.docker_tag.outputs.tag }}
50 changes: 26 additions & 24 deletions .github/workflows/tests.yml → .github/workflows/package-tests.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
name: Package tests

env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}

on:
pull_request:
branches:
Expand All @@ -16,13 +12,6 @@ on:
- master
- dev
workflow_call:
secrets:
DOCKER_USERNAME:
description: 'Docker Hub username'
required: true
DOCKER_TOKEN:
description: 'Docker Hub password'
required: true

permissions:
contents: read
Expand All @@ -33,13 +22,14 @@ jobs:
uses: ./.github/workflows/package-filter.yml
with:
num-commits: 0
ignore-missing-dev: false

tests:
name: Test "${{ matrix.package_name }}"
name: Test | ${{ matrix.package_name }}
needs: package-filter
strategy:
fail-fast: false
matrix: ${{fromJson(needs.package-filter.outputs.matrix)}}
matrix: ${{ fromJson(needs.package-filter.outputs.matrix) }}
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down Expand Up @@ -69,14 +59,26 @@ jobs:
poetry install
poetry run pytest -v
docker:
name: Build Docker images
needs: [package-filter, tests]
uses: ./.github/workflows/docker.yml
with:
matrix: ${{ needs.package-filter.outputs.matrix }}
push: false
secrets:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
- name: Docker | Tag
id: docker_tag
run: |
package_dir="${{ matrix.package_dir }}"
version=$(cat ${package_dir}/VERSION)
tag=polusai/${{ matrix.package_name }}:${version}
echo "tag will be ${tag}"
echo "tag=${tag}" >> $GITHUB_OUTPUT
- name: Docker | Setup Buildx
uses: docker/setup-buildx-action@v3
- name: Docker | Check if Image exists
run: |
tag=${{ steps.docker_tag.outputs.tag }}
docker pull ${tag} > /dev/null \
&& $(echo "::error::${tag} already exists on DockerHub" && exit 1) \
|| echo "success"
- name: Docker | Build Image
run: |
cp .gitignore ${{ matrix.package_dir }}/.dockerignore
cd "${{ matrix.package_dir }}"
tag=${{ steps.docker_tag.outputs.tag }}
docker build . -t ${tag}
# docker buildx build --platform linux/amd64,linux/arm64 -t ${tag} --push .
41 changes: 0 additions & 41 deletions .github/workflows/test-github-app.yml

This file was deleted.

0 comments on commit fba2ba5

Please sign in to comment.