|
| 1 | +name: Run Deployment When Pushing to Master |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + paths: |
| 9 | + - 'src/**' |
| 10 | + |
| 11 | +jobs: |
| 12 | + |
| 13 | + check-app-changes: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + outputs: |
| 16 | + app_changed: ${{ steps.check_app_changes.outputs.app_changed }} |
| 17 | + steps: |
| 18 | + - name: Checkout repo |
| 19 | + uses: actions/checkout@v3 |
| 20 | + with: |
| 21 | + token: ${{secrets.BIOKOTLINTOOLSCD}} |
| 22 | + fetch-depth: 0 |
| 23 | + |
| 24 | + - name: Check if app directory changed |
| 25 | + id: check_app_changes |
| 26 | + run: | |
| 27 | + LAST_RELEASE_TAG=$(git describe --tags $(git rev-list --tags --max-count=1)) |
| 28 | + echo "LAST_RELEASE_TAG was $LAST_RELEASE_TAG" |
| 29 | + LAST_RELEASE_COMMIT=$(git rev-list -n 1 $LAST_RELEASE_TAG) |
| 30 | + echo "LAST_RELEASE_COMMIT was $LAST_RELEASE_COMMIT" |
| 31 | + |
| 32 | + changed_files=$(git diff-tree --no-commit-id --name-only $LAST_RELEASE_COMMIT $GITHUB_SHA | grep '^src' || echo "none") |
| 33 | + echo "Changed app files: $changed_files" |
| 34 | + |
| 35 | + if [ "$changed_files" != "none" ]; then |
| 36 | + echo "App directory has changed since the last release." |
| 37 | + echo "app_changed=true" >> "$GITHUB_OUTPUT" |
| 38 | + else |
| 39 | + echo "App directory hasn't changed since the last release." |
| 40 | + echo "app_changed=false" >> "$GITHUB_OUTPUT" |
| 41 | + fi |
| 42 | +
|
| 43 | + build-and-release: |
| 44 | + runs-on: ubuntu-latest |
| 45 | + needs: check-app-changes |
| 46 | + if: ${{ needs.check-app-changes.outputs.app_changed == 'true' }} |
| 47 | + steps: |
| 48 | + |
| 49 | + - name: Checkout repo |
| 50 | + uses: actions/checkout@v3 |
| 51 | + with: |
| 52 | + token: ${{secrets.BIOKOTLINTOOLSCD}} |
| 53 | + |
| 54 | + - name: Setup Miniconda |
| 55 | + uses: conda-incubator/setup-miniconda@v2 |
| 56 | + with: |
| 57 | + auto-activate-base: true |
| 58 | + activate-environment: "" |
| 59 | + miniconda-version: "latest" |
| 60 | + |
| 61 | + # Uses semantic commits to automate version bumping. |
| 62 | + # No scope or "fix:" = PATCH, "feat:" or "minor:" = MINOR, "BREAKING CHANGE:", "major:", or fix/feat with appended "!" = MAJOR |
| 63 | + # Additional details: https://www.conventionalcommits.org/en/v1.0.0/ |
| 64 | + - name: Increment version |
| 65 | + run: | |
| 66 | + #!/bin/bash |
| 67 | + COMMIT_MSG=$(git log -1 --pretty=format:"%b" || git log -1 --pretty=format:"%B") |
| 68 | + source version.properties |
| 69 | + BUMP_TYPE="patchVersion" |
| 70 | +
|
| 71 | + if [[ $COMMIT_MSG == *"BREAKING CHANGE"* || $COMMIT_MSG == *"!"* || $COMMIT_MSG == *"major:"* ]]; then |
| 72 | + majorVersion=$((majorVersion + 1)) |
| 73 | + minorVersion=0 |
| 74 | + patchVersion=0 |
| 75 | + BUMP_TYPE="majorVersion" |
| 76 | + elif [[ $COMMIT_MSG == *"feat:"* || $COMMIT_MSG == *"minor:"* ]]; then |
| 77 | + minorVersion=$((minorVersion + 1)) |
| 78 | + patchVersion=0 |
| 79 | + BUMP_TYPE="minorVersion" |
| 80 | + else |
| 81 | + patchVersion=$((patchVersion + 1)) |
| 82 | + fi |
| 83 | + |
| 84 | + echo "majorVersion=$majorVersion" > version.properties |
| 85 | + echo "minorVersion=$minorVersion" >> version.properties |
| 86 | + echo "patchVersion=$patchVersion" >> version.properties |
| 87 | +
|
| 88 | + VERSION=$majorVersion.$minorVersion.$patchVersion |
| 89 | + RELEASE=$majorVersion.$minorVersion |
| 90 | + echo "COMMIT_MSG=$COMMIT_MSG" >> $GITHUB_ENV |
| 91 | + echo "VERSION=$VERSION" >> $GITHUB_ENV |
| 92 | + echo "RELEASE=$RELEASE" >> $GITHUB_ENV |
| 93 | + echo "BUMP_TYPE=$BUMP_TYPE" >> $GITHUB_ENV |
| 94 | +
|
| 95 | + - name: Commit version changes |
| 96 | + uses: EndBug/add-and-commit@v7 |
| 97 | + with: |
| 98 | + add: 'version.properties' |
| 99 | + message: Bump ${{ env.BUMP_TYPE }} |
| 100 | + |
| 101 | + author_name: Git Action Bot |
| 102 | + |
| 103 | + - name: Push changes |
| 104 | + uses: ad-m/github-push-action@master |
| 105 | + with: |
| 106 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 107 | + branch: ${{ github.ref }} |
| 108 | + |
| 109 | + - name: Set up JDK 17 |
| 110 | + uses: actions/setup-java@v3 |
| 111 | + with: |
| 112 | + distribution: temurin |
| 113 | + java-version: '17' |
| 114 | + cache: 'gradle' |
| 115 | + - name: Update applications.conf |
| 116 | + run: src/scripts/update_applications_conf.sh |
| 117 | + - name: Make gradlew executable |
| 118 | + run: chmod +x ./gradlew |
| 119 | + |
| 120 | + - name: Build BioKotlin Tools |
| 121 | + run: ./gradlew clean build --no-daemon |
| 122 | + |
| 123 | + - name: Get matching release |
| 124 | + uses: cardinalby/[email protected] |
| 125 | + id: matching_release |
| 126 | + env: |
| 127 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 128 | + with: |
| 129 | + releaseName: v${{ env.RELEASE }} |
| 130 | + doNotFailIfNotFound: 'true' |
| 131 | + |
| 132 | + - name: Delete matching release if exists |
| 133 | + if: steps.matching_release.outputs.id != '' |
| 134 | + run: | |
| 135 | + curl -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/releases/${{ steps.matching_release.outputs.id}}" |
| 136 | +
|
| 137 | + # Updates the latest release if just a new patch, drafts a new prerelease if major or minor version has changed |
| 138 | + - name: Make github release |
| 139 | + uses: svenstaro/upload-release-action@v2 |
| 140 | + with: |
| 141 | + repo_token: ${{ secrets.GITHUB_TOKEN }} |
| 142 | + release_name: v${{ env.RELEASE }} |
| 143 | + tag: ${{ env.VERSION }} |
| 144 | + file: build/distributions/biokotlin-tools.tar |
| 145 | + asset_name: BioKotlinTools-v${{ env.RELEASE }}.tar |
| 146 | + overwrite: ${{ env.BUMP_TYPE == 'patchVersion' }} |
| 147 | + prerelease: ${{ env.BUMP_TYPE != 'patchVersion' }} |
| 148 | + body: | |
| 149 | + ${{ steps.matching_release.outputs.body }} |
| 150 | + ${{ env.COMMIT_MSG }} |
| 151 | +
|
0 commit comments