From 85e21943438a9f725055e6f863bf1fe74c090b98 Mon Sep 17 00:00:00 2001 From: Hugo Saporetti Junior Date: Fri, 6 Dec 2024 17:59:45 -0300 Subject: [PATCH] Change release control -> github acitons - part - 1 --- .github/workflows/build-and-test.yml | 42 +++--- .github/workflows/create-release.yml | 154 ++++++++++++++++----- .github/workflows/publish.yml | 21 +-- .github/workflows/pypi-deploy.yml | 191 --------------------------- 4 files changed, 155 insertions(+), 253 deletions(-) delete mode 100644 .github/workflows/pypi-deploy.yml diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 9975936f..cd95ade6 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -12,11 +12,6 @@ on: default: '' required: false type: string - build_python3_10: - description: 'Check to build using python@3.10' - default: true - required: true - type: boolean build_python3_11: description: 'Check to build using python@3.11' default: true @@ -27,6 +22,13 @@ on: default: false required: true type: boolean + pull_request: + branches: + - '**' + paths: + - 'src/**' + - 'gradle/*.gradle' + - 'build.gradle' push: branches: - '**' @@ -35,6 +37,9 @@ on: - 'gradle/*.gradle' - 'build.gradle' +env: + PYRCC_VERSION: ${{ vars.PYRCC_VERSION }} + jobs: set-python-matrix: runs-on: "ubuntu-latest" @@ -43,17 +48,15 @@ jobs: steps: - name: Show Selected Input run: | - echo "Use Python@3.10: ${{ inputs.build_python3_10 || true }}" echo "Use Python@3.11: ${{ inputs.build_python3_11 || true }}" echo "Use Python@3.12: ${{ inputs.build_python3_12 || false }}" - name: Set Exclusion Matrix id: set-matrix-items run: | count=0 - all=('3.10' '3.11' '3.12') + all=('3.11' '3.12') while read -r next; do - if [[ (${next} == '3.10' && "false" == "${{ inputs.build_python3_10 || true }}") || - (${next} == '3.11' && "false" == "${{ inputs.build_python3_11 || true }}") || + if [[ (${next} == '3.11' && "false" == "${{ inputs.build_python3_11 || true }}") || (${next} == '3.12' && "false" == "${{ inputs.build_python3_12 || false }}") ]]; then item="{\"python-version\":\"${next}\"}," [[ "${JSON}" != *"${item}"* ]] && JSON="${JSON}${item}" @@ -61,7 +64,7 @@ jobs: fi done < <(printf '%s\n' "${all[@]}") [[ $JSON == *, ]] && JSON="${JSON%?}" - [[ ${count} -eq ${#all[@]} ]] && JSON="{\"python-version\":\"3.10\"}" + [[ ${count} -eq ${#all[@]} ]] && JSON="{\"python-version\":\"3.11\"}" JSON="[${JSON}]" echo "JSON: ${JSON}" echo "excludes=$( echo "${JSON}" )" >> $GITHUB_OUTPUT @@ -73,16 +76,14 @@ jobs: os: - 'ubuntu-latest' python-version: - - '3.10' - '3.11' - '3.12' exclude: ${{ fromJSON(needs.set-python-matrix.outputs.exclude-array) }} runs-on: ${{ matrix.os }} env: PYTHON_VERSION: ${{ matrix.python-version }} - PYRCC_VERSION: 5 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'true' - uses: actions/setup-java@v3 @@ -110,6 +111,17 @@ jobs: python3 -m pip install git+https://github.com/julian-r/python-magic.git - name: Update PIP run: pip install --upgrade pip - - name: Build HSPyLib modules + - name: Build preparation + id: build_init + run: | + echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT + - name: Build information + run: | + echo "## Build Information" >> $GITHUB_STEP_SUMMARY + echo "- JAVA: ${{ vars.JAVA_VERSION }}" >> $GITHUB_STEP_SUMMARY + echo "- GRADLE: ${{ vars.GRADLE_VERSION }}" >> $GITHUB_STEP_SUMMARY + echo "- PYTHON: ${{ matrix.python-version }}" >> $GITHUB_STEP_SUMMARY + echo "- BRANCH: ${{ steps.build_init.outputs.branch }}" >> $GITHUB_STEP_SUMMARY + - name: Build and Test run: | - gradle clean installModule build ${{ inputs.gradle_debug_params }} + gradle clean installBuildTools build ${{ inputs.gradle_debug_params }} diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index 91667f14..44d19f4b 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -2,52 +2,144 @@ name: create-release run-name: Create Release on: - workflow_dispatch: - inputs: - comment: - description: 'Release description' - default: 'New release' - required: false - type: string + push: + tags: + - "[0-9]+.[0-9]+.[0-9]+" + - "[0-9]+.[0-9]+.[0-9]+a[0-9]+" + - "[0-9]+.[0-9]+.[0-9]+b[0-9]+" + - "[0-9]+.[0-9]+.[0-9]+rc[0-9]+" + +env: + PACKAGE_NAME: "${vars.PACKAGE_NAME}" + OWNER: "${vars.OWNER}" + TAP_NAME: "${vars.TAP_NAME}" permissions: contents: write jobs: - init: - name: Init + details: runs-on: ubuntu-latest outputs: - version: ${{ steps.set-app-version.outputs.version }} + new_version: ${{ steps.release.outputs.new_version }} + suffix: ${{ steps.release.outputs.suffix }} + tag_name: ${{ steps.release.outputs.tag_name }} + steps: + - uses: actions/checkout@v4 + - name: Extract tag and Details + id: release + run: | + if [ "${{ github.ref_type }}" = "tag" ]; then + TAG_NAME=${GITHUB_REF#refs/tags/} + NEW_VERSION=$(echo $TAG_NAME | awk -F'-' '{print $1}') + SUFFIX=$(echo $TAG_NAME | grep -oP '[a-z]+[0-9]+' || echo "") + echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT" + echo "suffix=$SUFFIX" >> "$GITHUB_OUTPUT" + echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT" + echo "Version is $NEW_VERSION" + echo "Suffix is $SUFFIX" + echo "Tag name is $TAG_NAME" + else + echo "No tags found" + exit 1 + fi + + check_pypi: + needs: details + runs-on: ubuntu-latest steps: - - name: Checkout Repository - uses: actions/checkout@v3 - - name: Set App Version - id: set-app-version + - name: PyiI Information + run: | + response=$(curl -s https://pypi.org/pypi/${{ env.PACKAGE_NAME }}/json || echo "{}") + latest_previous_version=$(echo $response | jq --raw-output "select(.releases != null) | .releases | keys_unsorted | last") + if [ -z "$latest_previous_version" ]; then + echo "Package not found on PyPI." + latest_previous_version="0.0.0" + fi + echo "Latest version on PyPI: $latest_previous_version" + echo "latest_previous_version=$latest_previous_version" >> $GITHUB_ENV + - name: Ensure new Version run: | - appVersion=$(grep -e '.*' src/main/askai/.version) - echo "version=$(echo $appVersion)" >> $GITHUB_OUTPUT + NEW_VERSION=${{ needs.details.outputs.new_version }} + LATEST_VERSION=$latest_previous_version + if [ "$(printf '%s\n' "$LATEST_VERSION" "$NEW_VERSION" | sort -rV | head -n 1)" != "$NEW_VERSION" ] || [ "$NEW_VERSION" == "$LATEST_VERSION" ]; then + echo "The new version $NEW_VERSION is not greater than the latest version $LATEST_VERSION on PyPI." + exit 1 + else + echo "The new version $NEW_VERSION is greater than the latest version $LATEST_VERSION on PyPI." + fi + + build_and_test: + needs: [details, check_pypi] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: ${{ vars.JAVA_VERSION }} + - uses: gradle/gradle-build-action@v2 + with: + gradle-version: ${{ vars.GRADLE_VERSION }} + - name: Cache Gradle packages + uses: actions/cache@v3 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + restore-keys: ${{ runner.os }}-gradle + - uses: actions/setup-python@v3 + with: + python-version: ${{ vars.PYTHON_VERSION }} + - name: Install Python tools + run: gradle installBuildTools installModule ${{ gradle_debug_params }} + - name: Upload artifacts + uses: actions/upload-artifact@v3 + with: + name: dist + path: dist/ - create-release: - needs: init - name: Create Release + pypi_publish: + name: Upload release to PyPI + needs: [build_and_test, details] runs-on: ubuntu-latest + environment: + name: release + permissions: + id-token: write steps: - - name: Checkout Repository - uses: actions/checkout@v3 + - name: Download artifacts + uses: actions/download-artifact@v3 + with: + name: dist + path: dist/ + + - name: Publish distribution to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + + github_release: + name: Create GitHub Release + needs: [build_and_test, details] + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Create Changelog id: change-log uses: yorevs/hspylib/.github/actions/changelog@master with: tag-name: "v${{ needs.init.outputs.version }}" - - name: Create Release - uses: actions/create-release@v1 + - name: Download artifacts + uses: actions/download-artifact@v3 + with: + name: dist + path: dist/ + - name: Create GitHub Release + id: create_release env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: "v${{ needs.init.outputs.version }}" - release_name: "${{ vars.APP_NAME }}-v${{ needs.init.outputs.version }}-r${{ github.run_number }}" - body: | - ${{ steps.change-log.outputs.changelog }} - draft: false - prerelease: false + GH_TOKEN: ${{ github.token }} + run: | + gh release create ${{ needs.details.outputs.tag_name }} dist/* --title "${{ vars.PACKAGE_NAME }}-${{ needs.details.outputs.tag_name }}-rc${{ github.run_number }}" --generate-notes diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 7f901efd..ce3077fe 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -23,11 +23,6 @@ on: - 'patch' - 'minor' - 'major' - create_release: - description: 'Create a new GitHub release?' - type: boolean - required: false - default: false permissions: contents: write @@ -38,7 +33,7 @@ jobs: outputs: version: ${{ steps.publish-it.outputs.version }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-java@v3 with: distribution: temurin @@ -56,23 +51,17 @@ jobs: with: python-version: ${{ vars.PYTHON_VERSION }} - name: Install Python tools - run: gradle installBuildTools ${{ gradle_debug_params }} + run: gradle installBuildTools ${{ inputs.gradle_debug_params }} - name: Publish id: publish-it run: | bumpver update "--${{ inputs.revision_type }}" - version="$(awk '/./{line=$0} END{print line}' .version)" + version="$(awk '/./{line=$0} END{print line}' $(find . -type f -name .version))" echo "version=$( echo "$version" )" >> $GITHUB_OUTPUT git config --global user.name "$(git log -n 1 --pretty=format:%an)" git config --global user.email "$(git log -n 1 --pretty=format:%ae)" git config github.token "${{ secrets.GITHUB_TOKEN }}" git commit -a -m "[@${{ github.actor }}] ${{ inputs.comment }}" git pull --rebase -Xtheirs && git push --atomic origin HEAD - - create-release: - runs-on: ubuntu-latest - steps: - - uses: ./.github/workflows/create-release.yml - with: - comment: ${{ inputs.comment }} - + git tag -a v"$version" -m "${{ inputs.comment }}" + git push origin --tags diff --git a/.github/workflows/pypi-deploy.yml b/.github/workflows/pypi-deploy.yml deleted file mode 100644 index 71526fe6..00000000 --- a/.github/workflows/pypi-deploy.yml +++ /dev/null @@ -1,191 +0,0 @@ -name: pypi-deploy -run-name: PyPi Deploy - -on: - workflow_dispatch: - inputs: - pypi_env: - description: 'PyPi instance to publish ?' - default: 'pypi-test' - required: true - type: choice - options: - - pypi-test - - pypi-prod - cfman: - description: 'Deploy HSPyLib-Cfman ?' - default: false - required: true - type: boolean - clitt: - description: 'Deploy HSPyLib-Clitt ?' - default: false - required: true - type: boolean - datasource: - description: 'Deploy HSPyLib-Datasource ?' - default: false - required: true - type: boolean - firebase: - description: 'Deploy HSPyLib-Firebase ?' - default: false - required: true - type: boolean - hqt: - description: 'Deploy HSPyLib-HQT ?' - default: false - required: true - type: boolean - hspylib: - description: 'Deploy HSPyLib-Core ?' - default: false - required: true - type: boolean - kafman: - description: 'Deploy HSPyLib-Kafman ?' - default: false - required: true - type: boolean - setman: - description: 'Deploy HSPyLib-Setman ?' - default: false - required: true - type: boolean - vault: - description: 'Deploy HSPyLib-Vault ?' - default: false - required: true - type: boolean - -permissions: - contents: write - -jobs: - set-env-matrix: - runs-on: ubuntu-latest - outputs: - matrix: ${{ steps.set-matrix-items.outputs.matrix }} - modules: ${{ steps.set-matrix-items.outputs.modules }} - steps: - - name: Check Branch - run: | - if [[ "${{ inputs.pypi_env }}" == "pypi-test" && - "${{ github.ref_name }}" != 'develop' ]]; then - echo "Can only deploy to 'pypi-test' from develop" - exit 1 - fi - if [[ "${{ inputs.pypi_env }}" == "pypi-prod" && - "${{ github.ref_name }}" != 'master' ]]; then - echo "Can only deploy to 'pypi-prod' from master" - exit 1 - fi - - name: Set Matrix Items - id: set-matrix-items - run: | - selected=() - modules=('cfman' 'clitt' 'datasource' 'firebase' 'hqt' 'hspylib' 'kafman' 'setman' 'vault') - JSON="{\"include\":[" - # Loop by lines - while read -r module; - do - if [[ (${module} == 'cfman' && "true" == "${{inputs.cfman}}") || - (${module} == 'clitt' && "true" == "${{inputs.clitt}}") || - (${module} == 'datasource' && "true" == "${{inputs.datasource}}") || - (${module} == 'firebase' && "true" == "${{inputs.firebase}}") || - (${module} == 'hqt' && "true" == "${{inputs.hqt}}") || - (${module} == 'hspylib' && "true" == "${{inputs.hspylib}}") || - (${module} == 'kafman' && "true" == "${{inputs.kafman}}") || - (${module} == 'setman' && "true" == "${{inputs.setman}}") || - (${module} == 'vault' && "true" == "${{inputs.vault}}")]] - then - selected+=("${module}") - JSONline="{\"module\": \"${module}\"}," - if [[ "$JSON" != *"$JSONline"* ]]; then - JSON="$JSON$JSONline" - fi - fi - done < <(printf '%s\n' "${modules[@]}") - # Remove last "," - if [[ $JSON == *, ]]; then - JSON="${JSON%?}" - fi - # Add closing brackets - JSON="$JSON]}" - echo "matrix=$( echo "$JSON" )" >> $GITHUB_OUTPUT - echo "modules=$( echo "${selected[*]}" )" >> $GITHUB_OUTPUT - - update-version: - needs: - - set-env-matrix - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-java@v3 - with: - distribution: temurin - java-version: ${{ vars.JAVA_VERSION }} - - uses: gradle/gradle-build-action@v2 - with: - gradle-version: ${{ vars.GRADLE_VERSION }} - - uses: actions/setup-python@v3 - with: - python-version: ${{ vars.PYTHON_VERSION }} - - name: Install Python tools - run: gradle installBuildTools - - name: Patch Versions & Commit - run: | - for module in ${{ needs.set-env-matrix.outputs.modules }}; - do - gradle "${module}:patchVersion" - done - if [[ -n $(git status --porcelain) ]]; then - git config --global user.name "$(git log -n 1 --pretty=format:%an)" - git config --global user.email "$(git log -n 1 --pretty=format:%ae)" - git config github.token "${{ inputs.github-token }}" - git commit -a -m "[@${{ github.actor }}] Push for new deployment -> '${{ matrix.module }}'" - git pull --rebase -Xtheirs && git push --atomic origin HEAD - fi - - deploy: - needs: - - set-env-matrix - - update-version - strategy: - fail-fast: false - matrix: ${{ fromJson(needs.set-env-matrix.outputs.matrix) }} - runs-on: ubuntu-latest - environment: ${{ inputs.pypi_env }} - env: - PYPI_REPOSITORY: ${{ vars.PYPI_REPOSITORY }} - PYPI_MODULE_URL: ${{ vars.PYPI_MODULE_URL }} - PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }} - PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - PYPI_MODULE: ${{ matrix.module }} - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-java@v3 - with: - distribution: temurin - java-version: ${{ vars.JAVA_VERSION }} - - uses: gradle/gradle-build-action@v2 - with: - gradle-version: ${{ vars.GRADLE_VERSION }} - - name: Cache Gradle packages - uses: actions/cache@v3 - with: - path: ~/.gradle/caches - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} - restore-keys: ${{ runner.os }}-gradle - - uses: actions/setup-python@v3 - with: - python-version: ${{ vars.PYTHON_VERSION }} - - name: Install Python tools - run: gradle installBuildTools - - name: Publish modules to PyPi - run: | - echo "Deploying module: (${{ matrix.module }}) to: ${{ inputs.pypi_env }} -> ${{ env.PYPI_REPOSITORY }}" - gradle ${{ matrix.module }}:publish -Pno-patch=true - - name: Check published package - run: | - gradle ${{ matrix.module }}:pypiShow