Package Release #23
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Package Release | |
env: | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} | |
on: | |
workflow_dispatch: | |
inputs: | |
num-commits: | |
description: "The of commits to check for updated packages. If 0, the action will check all commits on the branch. For any larger value, the action will check the last n commits for any updated packages." | |
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 | |
type: string | |
default: 'image-tools' | |
workflow_call: | |
inputs: | |
num-commits: | |
description: "The of commits to check for updated packages. If 0, the action will check all commits on the master branch. For any larger value, the action will check the last n commits for any updated packages." | |
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' | |
required: true | |
type: string | |
secrets: | |
DOCKER_USERNAME: | |
description: 'Docker Hub username' | |
required: true | |
DOCKER_TOKEN: | |
description: 'Docker Hub password' | |
required: true | |
permissions: | |
contents: write | |
jobs: | |
package-filter: | |
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 }} | |
if: github.repository == 'polusai/${{ github.event.inputs.repo_name }}' | |
needs: package-filter | |
strategy: | |
fail-fast: false | |
matrix: ${{ fromJson(needs.package-filter.outputs.matrix) }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ref: ${{ github.event.inputs.branch }} | |
persist-credentials: false | |
- 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: Token | Use the token | |
env: | |
GH_TOKEN: ${{ steps.generate_token.outputs.token }} | |
run: | | |
gh api octocat | |
- name: Python | Setup | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.9' | |
- name: Python | Install bump2version | |
run: | | |
python -m pip install --upgrade pip | |
pip install bump2version | |
- name: Python | Bump Version Release | |
id: bump_version | |
run: | | |
pkg_dir=${{ matrix.package_dir }} | |
cd "${pkg_dir}" | |
# check if the package has a dev version | |
if [[ "$(cat VERSION)" != *dev* ]] | |
then | |
msg="${pkg_dir} does not have a dev version" | |
${{ github.event.inputs.ignore-missing-dev }} && echo "::warning::${msg}" || $(echo "::error::${msg}" && exit 1) | |
else | |
bump2version release --no-commit | |
fi | |
# check if the package has been released and update the output | |
if [[ $(git status --porcelain) ]] | |
then | |
echo "released=true" >> $GITHUB_OUTPUT | |
else | |
echo "released=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Git | Commit | |
if: steps.bump_version.outputs.released == 'true' | |
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: Git | Push | |
if: steps.bump_version.outputs.released == 'true' | |
uses: ad-m/github-push-action@master | |
with: | |
force: true | |
github_token: ${{ steps.generate_token.outputs.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 }} |