Skip to content

Commit

Permalink
Change release control -> github acitons - part - 1
Browse files Browse the repository at this point in the history
  • Loading branch information
yorevs committed Dec 6, 2024
1 parent 80d2d36 commit 85e2194
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 253 deletions.
42 changes: 27 additions & 15 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,6 +22,13 @@ on:
default: false
required: true
type: boolean
pull_request:
branches:
- '**'
paths:
- 'src/**'
- 'gradle/*.gradle'
- 'build.gradle'
push:
branches:
- '**'
Expand All @@ -35,6 +37,9 @@ on:
- 'gradle/*.gradle'
- 'build.gradle'

env:
PYRCC_VERSION: ${{ vars.PYRCC_VERSION }}

jobs:
set-python-matrix:
runs-on: "ubuntu-latest"
Expand All @@ -43,25 +48,23 @@ 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}"
((count+=1))
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
Expand All @@ -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
Expand Down Expand Up @@ -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 }}
154 changes: 123 additions & 31 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 5 additions & 16 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Loading

0 comments on commit 85e2194

Please sign in to comment.