From 2dd10b6b42b065e9d9b068c0fef10c3ce5049f98 Mon Sep 17 00:00:00 2001 From: Najib <32004868+nishaq503@users.noreply.github.com> Date: Mon, 5 Feb 2024 07:36:02 -0500 Subject: [PATCH] ci: updating release action (#513) --- .github/workflows/package-filter.yml | 37 ++++++++----- .github/workflows/package-release.yml | 76 +++++++++++++++++++-------- test.txt | 0 3 files changed, 78 insertions(+), 35 deletions(-) delete mode 100644 test.txt diff --git a/.github/workflows/package-filter.yml b/.github/workflows/package-filter.yml index 1eb543541..502b8ce51 100644 --- a/.github/workflows/package-filter.yml +++ b/.github/workflows/package-filter.yml @@ -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 @@ -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 @@ -43,7 +47,7 @@ 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" @@ -51,7 +55,7 @@ jobs: 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 @@ -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 @@ -108,14 +120,14 @@ 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 @@ -123,3 +135,4 @@ jobs: # Set the output echo "matrix=$( echo "$JSON" )" >> $GITHUB_OUTPUT + echo "list=$( echo "$PACKAGE_DIRS" )" >> $GITHUB_OUTPUT diff --git a/.github/workflows/package-release.yml b/.github/workflows/package-release.yml index c752277a6..49c1f95d9 100644 --- a/.github/workflows/package-release.yml +++ b/.github/workflows/package-release.yml @@ -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 @@ -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: @@ -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: | @@ -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 }}" diff --git a/test.txt b/test.txt deleted file mode 100644 index e69de29bb..000000000