Skip to content

Commit

Permalink
ci: updating release action (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
nishaq503 authored Feb 5, 2024
1 parent cc2097f commit 2dd10b6
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 35 deletions.
37 changes: 25 additions & 12 deletions .github/workflows/package-filter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ on:
matrix:
description: "The directories containing the updated packages"
value: ${{ jobs.package-filter.outputs.matrix }}
list:
description: "The list of directories containing the updated packages"
value: ${{ jobs.package-filter.outputs.list }}

permissions:
contents: read
Expand All @@ -27,6 +30,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.package-filter.outputs.matrix }}
list: ${{ steps.package-filter.outputs.list }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -43,15 +47,15 @@ jobs:
# echo the base ref
base_ref=${{ github.base_ref }}
if [[ -z "$base_ref" ]]
if [ -z "$base_ref" ]
then
base_ref="master"
echo "::warning::Action not running on PR, defaulting to base branch to master"
fi
echo "The base ref is $base_ref"
# Get the comparison point in the repo
if [[ ${{ inputs.num-commits }} == 0 ]]
if [ ${{ inputs.num-commits }} == 0 ]
then
comparison_point="origin/${base_ref}"
else
Expand All @@ -64,39 +68,47 @@ jobs:
pkg_dir=$(dirname ${changed_file})
# Exclude the root directory
if [[ "$pkg_dir" == "." ]]
if [ "$pkg_dir" == "." ]
then
continue
fi
# Check if the changed file is a pyproject.toml file
if [[ "$(basename ${changed_file})" == *"pyproject.toml"* ]]
if [ "$(basename ${changed_file})" == *"pyproject.toml"* ]
then
pkg_dir=$(dirname ${changed_file})
# Check that the package has all the necessary companion files
for companion_file in $COMPANION_FILES
do
if [[ ! -f "$pkg_dir/$companion_file" ]]
echo "Checking for $companion_file in $pkg_dir"
if [ ! -f "${pkg_dir}/${companion_file}" ]
then
echo "::error::${pkg_dir} does not have a $companion_file file" && exit 1
fi
done
# Check that the version is a dev version
if [[ "$(cat ${pkg_dir}/VERSION)" != *"dev"* ]]
echo "Checking for dev version in $pkg_dir"
if [ $(cat $pkg_dir/VERSION) != *"dev"* ]
then
msg="${pkg_dir} does not have a dev version"
${{ inputs.ignore-missing-dev }} && echo "::warning::${msg}" || $(echo "::error::${msg}" && exit 1)
if [ ${{ inputs.ignore-missing-dev }} ]
then
echo "::warning::${msg}"
else
echo "::error::${msg}" && exit 1
fi
fi
PACKAGE_DIRS="$PACKAGE_DIRS ${pkg_dir}"
fi
done
# Trim leading whitespace
PACKAGE_DIRS=$(echo $PACKAGE_DIRS | xargs)
# Check if any packages were found
echo "The updated packages are $PACKAGE_DIRS"
if [[ -z "$PACKAGE_DIRS" ]]
if [ -z "$PACKAGE_DIRS" ]
then
echo "::error::No updated packages were found" && exit 1
fi
Expand All @@ -108,18 +120,19 @@ jobs:
package_name=$(basename $package_dir)
JSON_LINE="{\"package_dir\": \"${package_dir}\", \"package_name\": \"${package_name}\"},"
# Add the JSON line to the JSON string if it is not already included
if [[ ! "$JSON" == *"$JSON_LINE"* ]]
if [ ! "$JSON" == *"$JSON_LINE"* ]
then
JSON="$JSON$JSON_LINE"
fi
done
# Remove trailing comma and add closing brackets
if [[ $JSON == *, ]]
if [ "$JSON" == *"," ]
then
JSON="${JSON%?}"
fi
JSON="$JSON]}"
# Set the output
echo "matrix=$( echo "$JSON" )" >> $GITHUB_OUTPUT
echo "list=$( echo "$PACKAGE_DIRS" )" >> $GITHUB_OUTPUT
76 changes: 53 additions & 23 deletions .github/workflows/package-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,9 @@ jobs:
ignore-missing-dev: ${{ fromJson(github.event.inputs.ignore-missing-dev) }}

package-release:
name: Release | ${{ matrix.package_name }}
name: Release Versions
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
Expand Down Expand Up @@ -95,24 +92,41 @@ jobs:
- 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
cur_dir=$GITHUB_WORKSPACE
released_packages=""
for pkg_dir in ${{ needs.package-filter.outputs.list }}
do
echo "Bumping version for ${pkg_dir}"
echo "cd-ing to ${pkg_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"
if ${{ github.event.inputs.ignore-missing-dev }}
then
echo "::warning::${msg}"
else
echo "::error::${msg}" && exit 1
fi
else
bump2version release --no-commit
fi
# check if the package has been released and update the output
if [[ $(git status --porcelain) ]]
then
released_packages="${released_packages} ${pkg_dir}"
fi
cd ${cur_dir}
done
# 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
# Trim leading whitespace
released_packages=$(echo "${released_packages}" | xargs)
echo "Released packages: ${released_packages}"
echo "released_packages=${released_packages}" >> $GITHUB_OUTPUT
- name: Git | Commit
if: steps.bump_version.outputs.released == 'true'
env:
Expand All @@ -121,13 +135,29 @@ jobs:
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 }}"
git commit -a -m "build: Bumped release version for ${{ steps.bump_version.outputs.released_packages }}"
- 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 }}

docker:
name: Docker | ${{ matrix.package_name }}
if: github.repository == 'polusai/${{ github.event.inputs.repo_name }}'
needs: [package-filter, package-release]
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: Docker | Tag
id: docker_tag
run: |
Expand All @@ -149,7 +179,7 @@ jobs:
docker pull ${tag} > /dev/null \
&& $(echo "::error::${tag} already exists on DockerHub" && exit 1) \
|| echo "success"
- name: Docekr | Push Image
- name: Docker | Push Image
uses: docker/build-push-action@v5
with:
context: "{{defaultContext}}:${{ matrix.package_dir }}"
Expand Down
Empty file removed test.txt
Empty file.

0 comments on commit 2dd10b6

Please sign in to comment.