diff --git a/.github/workflows/.release-created.yml b/.github/workflows/.release-created.yml new file mode 100644 index 0000000..9f46276 --- /dev/null +++ b/.github/workflows/.release-created.yml @@ -0,0 +1,42 @@ + +name: Release Branch Created + +# Run whenever a ref is created https://docs.github.com/en/actions/reference/events-that-trigger-workflows#create +on: + create + +jobs: + # First job in the workflow builds and verifies the software artifacts + bump: + name: Bump minor version on develop + # The type of runner that the job will run on + runs-on: ubuntu-latest + # Only run if ref created was a release branch + if: + ${{ startsWith(github.ref, 'refs/heads/release/') }} + steps: + # Checks-out the develop branch + - uses: actions/checkout@v4 + with: + ref: 'refs/heads/develop' + + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Install Poetry + uses: abatilo/actions-poetry@v3 + with: + poetry-version: 1.8.5 + + - name: Bump minor version + run: | + poetry version ${GITHUB_REF#refs/heads/release/} + poetry version preminor + echo "software_version=$(poetry version | awk '{print $2}')" >> $GITHUB_ENV + - name: Commit Version Bump + run: | + git config --global user.name 'podaac-hitide-backfill-lambdas bot' + git config --global user.email 'podaac-hitide-backfill-lambdas@noreply.github.com' + git commit -am "/version ${{ env.software_version }}" + git push diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 31c62a6..d23d444 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,150 +34,60 @@ jobs: - name: Install Poetry uses: abatilo/actions-poetry@v3 with: - poetry-version: 1.8.1 + poetry-version: 1.8.5 + ######################################################################### - # Versioning (featuring weird gradle output work-arounds) + # Versioning Summary ######################################################################### - # NOTE: This step is platform-specific - # Retrieve version information for use in the other versioning steps - - name: Get version - id: get-version - run: | - echo "the_service=${{ github.event.repository.name }}" >> $GITHUB_ENV - echo "the_env=$(printenv)" >> $GITHUB_ENV - echo "${{ github.event.repository.name }}" - echo "pyproject_name=$(poetry version | awk '{print $1}')" >> $GITHUB_ENV - poetry version > .temp_version.out - cat .temp_version.out - the_version=$(cat .temp_version.out |grep -v Downloading |grep -v '%' |sed -e 's/hitide-backfill-lambdas *//') - rm .temp_version.out - echo "old_version=$the_version" >> $GITHUB_ENV - echo "the_version=$the_version" >> $GITHUB_ENV - echo "Initial Version: $the_version" - # Pre-Alpha Logic - Use the project version number and add the short hash - # to it - - name: Bump pre-alpha version - # If triggered by push to a feature branch - if: | - startsWith(github.ref, 'refs/heads/issue') || - startsWith(github.ref, 'refs/heads/dependabot/') || - startsWith(github.ref, 'refs/heads/feature/') - # At pre-alpha, append git-commit to version, set it into gradle - # property, read the version out and set to build_service_version + - name: Version Management + id: versioning run: | - the_version=$(echo "${{ env.the_version }}" | sed -e "s/-alpha.*//g") - the_version=$(echo "$the_version" | sed -e "s/-rc.*//g") - new_version="${the_version}+$(git rev-parse --short HEAD)" - echo "the_version=${new_version}" >> $GITHUB_ENV - echo "software_version=${new_version}" >> $GITHUB_ENV + current_version=$(poetry version -s) + base_version=$(echo "$current_version" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+') + + # Version calculation based on branch + if [[ "${{ github.ref }}" =~ ^refs/heads/(issue|feature|dependabot)/ ]]; then + new_version="${base_version%%-*}+$(git rev-parse --short HEAD)" + echo "TARGET_ENV_UPPERCASE=SIT" >> $GITHUB_ENV + elif [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then + echo "TARGET_ENV_UPPERCASE=SIT" >> $GITHUB_ENV + new_version=$(poetry version prerelease -s) + elif [[ "${{ github.ref }}" =~ ^refs/heads/release/ ]]; then + echo "TARGET_ENV_UPPERCASE=UAT" >> $GITHUB_ENV + if [[ ${current_version} =~ rc ]]; then + new_version=$(poetry version prerelease -s) + else + new_version="${GITHUB_REF#refs/heads/release/}rc1" + fi + elif [[ "${{ github.ref }}" == "refs/heads/main" ]]; then + echo "TARGET_ENV_UPPERCASE=OPS" >> $GITHUB_ENV + new_version=${base_version} + fi + echo "new_version=${new_version}" >> $GITHUB_ENV - echo "Github REF: ${{ github.ref }}" - # Alpha Logic - Use the project version number and add -alpha.1 or bump - # alpha number - - name: Bump alpha version - env: - VERSION: ${{ env.the_version }} - # If triggered by push to the develop branch - if: ${{ github.ref == 'refs/heads/develop' }} + - name: Override Environment for Deploy Command + if: contains(github.event.head_commit.message, '/deploy') run: | - if [[ ${VERSION} == *"-alpha"* ]]; then - alpha_number=$(echo "${VERSION}" | sed -e "s/^.*-alpha.//g") - alpha_number=$(echo "$alpha_number" | sed -e "s/-rc.*//g") - alpha_number=$((alpha_number+1)) - the_version=$(echo "$the_version" | sed -e "s/-alpha.*//g") - the_version=$(echo "$the_version" | sed -e "s/-rc.*//g") - the_version="${the_version}-alpha.$alpha_number" - echo "software_version=${the_version}" >> $GITHUB_ENV - echo "the_version=${the_version}" >> $GITHUB_ENV - else - the_version="${{ env.the_version }}-alpha.1" - echo "software_version=${the_version}" >> $GITHUB_ENV - echo "the_version=${the_version}" >> $GITHUB_ENV + message="${{ github.event.head_commit.message }}" + override_env=$(echo "$message" | grep -oE '/deploy (sit|uat)' | awk '{print $2}') + if [[ -n "$override_env" ]]; then + override_env_upper=$(echo "$override_env" | tr '[:lower:]' '[:upper:]') + echo "TARGET_ENV_UPPERCASE=${override_env_upper}" >> $GITHUB_ENV + echo "TARGET_ENV_LOWERCASE=${override_env}" >> $GITHUB_ENV + echo "Overriding deployment target to: ${override_env_upper}" fi - echo "new_version=${the_version}" >> $GITHUB_ENV - echo "venue=sit" >> $GITHUB_ENV - echo "TARGET_ENV_UPPERCASE=SIT" >> $GITHUB_ENV - # Release Candidate Logic - Remove -alpha* and add -rc.1, or bump the rc - # number - - name: Bump rc version - if: ${{ startsWith(github.ref, 'refs/heads/release/') }} - env: - VERSION: ${{ env.the_version }} - COMMIT_VERSION: ${{ github.ref }} + - name: Set Lowercase Environment run: | - commit_version=$COMMIT_VERSION - commit_version=$(echo "${commit_version}" |sed -e "s/^.*\///g") - commit_version=$(echo "${commit_version}" |sed -e "s/-alpha.*//g") - commit_version=$(echo "${commit_version}" |sed -e "s/-rc.*//g") - echo "COMMIT VERSION: $commit_version" - file_version=${VERSION} - file_version=$(echo "${file_version}" |sed -e "s/-alpha.*//g") - file_version=$(echo "${file_version}" |sed -e "s/-rc.*//g") - echo "FILE VERSION: $file_version" - if [[ "$commit_version" != "$file_version" ]]; then - echo "Commit version and file version are different, using commit version" - VERSION=$commit_version - fi - if [[ ${VERSION} == *"-rc"* ]]; then - echo "Bumping up the release candidate number from ${VERSION}" - rc_number=$(echo "${VERSION}" | sed -e "s/^.*-rc.//g") - rc_number=$(echo "${rc_number}" | sed -e "s/-alpha.*//g") - rc_number=$((rc_number+1)) - the_version=$(echo "$the_version" | sed -e "s/-rc.*//g") - the_version=$(echo "$the_version" | sed -e "s/-alpha.*//g") - VERSION="${the_version}-rc.${rc_number}" - else - echo "Initializing the first release candidate for ${VERSION}" - VERSION=$(echo "${VERSION}" |sed -e "s/-alpha.*//g") - VERSION="${VERSION}-rc.1" - fi - echo "software_version=${VERSION}" >> $GITHUB_ENV - echo "the_version=${VERSION}" >> $GITHUB_ENV - echo "new_version=${VERSION}" >> $GITHUB_ENV - echo "venue=uat" >> $GITHUB_ENV - echo "TARGET_ENV_UPPERCASE=UAT" >> $GITHUB_ENV + echo "TARGET_ENV_LOWERCASE=$(echo ${{ env.TARGET_ENV_UPPERCASE }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV - - # Release Logic - - name: Release version - # If triggered by push to the main branch - if: ${{ startsWith(github.ref, 'refs/heads/main') }} - env: - VERSION: ${{ env.the_version }} - # Remove -rc.* from end of version string - run: | - software_version=$(echo "${VERSION}" | sed -e s/-rc.*//g) - software_version=$(echo "${software_version}" | sed -e s/-alpha.*//g) - echo "software_version=$software_version" >> $GITHUB_ENV - echo "new_version=$software_version" >> $GITHUB_ENV - echo "the_version=$software_version" >> $GITHUB_ENV - echo "venue=ops" >> $GITHUB_ENV - echo "TARGET_ENV_UPPERCASE=OPS" >> $GITHUB_ENV - - - ######################################################################### - # Versioning Summary - ######################################################################### - - name: Versioning Summary - run: | - echo "the_service: ${{ env.the_service }}" - echo "old version : ${{ env.old_version }}" - echo "new version : ${{ env.new_version }}" - echo "the_env: ${{ env.the_env }}" - echo "software_version: ${{ env.software_version }}" - echo "GITHUB REF: ${{ github.ref }}" - echo "VENUE: ${{ env.venue }}" - echo "Target Env Uppercase: ${{ env.TARGET_ENV_UPPERCASE }}" - - # NOTE: This step is platform-specific # Update the version number in the application package itself - name: Update version number in the application package run: | - poetry version ${{ env.the_version }} + poetry version ${{ env.new_version }} ######################################################################### # Install & Test & Snyk @@ -245,12 +155,12 @@ jobs: run: | git config user.name "${GITHUB_ACTOR}" git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" - git commit -am "/version ${{ env.the_version }}" + git commit -am "/version ${{ env.new_version }}" git push - name: Push Tag env: - VERSION: ${{ env.the_version }} + VERSION: ${{ env.new_version }} if: | github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/main' || @@ -280,7 +190,7 @@ jobs: ls -la ls -la package cd package/; zip -r ../terraform/hitide-backfill-lambda.zip . -x '*.pyc' - cd ../; cd terraform; zip -r ../hitide-backfill-lambdas-${{ env.the_version }}.zip * + cd ../; cd terraform; zip -r ../hitide-backfill-lambdas-${{ env.new_version }}.zip * - name: Upload Release Artifacts if: | @@ -292,9 +202,9 @@ jobs: github.event.head_commit.message == '/deploy sandbox' uses: ncipollo/release-action@v1.14.0 with: - tag: ${{ env.the_version }} + tag: ${{ env.new_version }} artifacts: "*.zip" token: ${{ secrets.GITHUB_TOKEN }} - body: "Version ${{ env.the_version }}" + body: "Version ${{ env.new_version }}" makeLatest: "${{ github.ref == 'refs/heads/main' }}" prerelease: "${{ github.ref != 'refs/heads/main' }}" diff --git a/CHANGELOG.md b/CHANGELOG.md index 86dc116..a187b20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Poetry Update +- Update versioning in github actions ### Deprecated ### Removed ### Fixed diff --git a/pyproject.toml b/pyproject.toml index 82f6aa4..c354152 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "hitide-backfill-lambdas" -version = "0.5.0-alpha.2" +version = "0.5.0a2" description = "" authors = ["podaac-tva "] license = "Apache-2.0"