Testing CI #1 #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run Deployment When Pushing to Master | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
paths: | |
- 'src/**' | |
jobs: | |
check-app-changes: | |
runs-on: ubuntu-latest | |
outputs: | |
app_changed: ${{ steps.check_app_changes.outputs.app_changed }} | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v3 | |
with: | |
token: ${{secrets.BIOKOTLINTOOLSCD}} | |
fetch-depth: 0 | |
- name: Check if app directory changed | |
id: check_app_changes | |
run: | | |
LAST_RELEASE_TAG=$(git describe --tags $(git rev-list --tags --max-count=1)) | |
echo "LAST_RELEASE_TAG was $LAST_RELEASE_TAG" | |
LAST_RELEASE_COMMIT=$(git rev-list -n 1 $LAST_RELEASE_TAG) | |
echo "LAST_RELEASE_COMMIT was $LAST_RELEASE_COMMIT" | |
changed_files=$(git diff-tree --no-commit-id --name-only $LAST_RELEASE_COMMIT $GITHUB_SHA | grep '^src' || echo "none") | |
echo "Changed app files: $changed_files" | |
if [ "$changed_files" != "none" ]; then | |
echo "App directory has changed since the last release." | |
echo "app_changed=true" >> "$GITHUB_OUTPUT" | |
else | |
echo "App directory hasn't changed since the last release." | |
echo "app_changed=false" >> "$GITHUB_OUTPUT" | |
fi | |
build-and-release: | |
runs-on: ubuntu-latest | |
needs: check-app-changes | |
if: ${{ needs.check-app-changes.outputs.app_changed == 'true' }} | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v3 | |
with: | |
token: ${{secrets.BIOKOTLINTOOLSCD}} | |
- name: Setup Miniconda | |
uses: conda-incubator/setup-miniconda@v2 | |
with: | |
auto-activate-base: true | |
activate-environment: "" | |
miniconda-version: "latest" | |
# Uses semantic commits to automate version bumping. | |
# No scope or "fix:" = PATCH, "feat:" or "minor:" = MINOR, "BREAKING CHANGE:", "major:", or fix/feat with appended "!" = MAJOR | |
# Additional details: https://www.conventionalcommits.org/en/v1.0.0/ | |
- name: Increment version | |
run: | | |
#!/bin/bash | |
COMMIT_MSG=$(git log -1 --pretty=format:"%b" || git log -1 --pretty=format:"%B") | |
source version.properties | |
BUMP_TYPE="patchVersion" | |
if [[ $COMMIT_MSG == *"BREAKING CHANGE"* || $COMMIT_MSG == *"!"* || $COMMIT_MSG == *"major:"* ]]; then | |
majorVersion=$((majorVersion + 1)) | |
minorVersion=0 | |
patchVersion=0 | |
BUMP_TYPE="majorVersion" | |
elif [[ $COMMIT_MSG == *"feat:"* || $COMMIT_MSG == *"minor:"* ]]; then | |
minorVersion=$((minorVersion + 1)) | |
patchVersion=0 | |
BUMP_TYPE="minorVersion" | |
else | |
patchVersion=$((patchVersion + 1)) | |
fi | |
echo "majorVersion=$majorVersion" > version.properties | |
echo "minorVersion=$minorVersion" >> version.properties | |
echo "patchVersion=$patchVersion" >> version.properties | |
VERSION=$majorVersion.$minorVersion.$patchVersion | |
RELEASE=$majorVersion.$minorVersion | |
echo "COMMIT_MSG=$COMMIT_MSG" >> $GITHUB_ENV | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
echo "RELEASE=$RELEASE" >> $GITHUB_ENV | |
echo "BUMP_TYPE=$BUMP_TYPE" >> $GITHUB_ENV | |
- name: Commit version changes | |
uses: EndBug/add-and-commit@v7 | |
with: | |
add: 'version.properties' | |
message: Bump ${{ env.BUMP_TYPE }} | |
author_email: [email protected] | |
author_name: Git Action Bot | |
- name: Push changes | |
uses: ad-m/github-push-action@master | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: ${{ github.ref }} | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: temurin | |
java-version: '17' | |
cache: 'gradle' | |
- name: Update applications.conf | |
run: src/scripts/update_applications_conf.sh | |
- name: Make gradlew executable | |
run: chmod +x ./gradlew | |
- name: Build BioKotlin Tools | |
run: ./gradlew clean build --no-daemon | |
- name: Get matching release | |
uses: cardinalby/[email protected] | |
id: matching_release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
releaseName: v${{ env.RELEASE }} | |
doNotFailIfNotFound: 'true' | |
- name: Delete matching release if exists | |
if: steps.matching_release.outputs.id != '' | |
run: | | |
curl -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/releases/${{ steps.matching_release.outputs.id}}" | |
# Updates the latest release if just a new patch, drafts a new prerelease if major or minor version has changed | |
- name: Make github release | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
release_name: v${{ env.RELEASE }} | |
tag: ${{ env.VERSION }} | |
file: build/distributions/biokotlin-tools.tar | |
asset_name: BioKotlinTools-v${{ env.RELEASE }}.tar | |
overwrite: ${{ env.BUMP_TYPE == 'patchVersion' }} | |
prerelease: ${{ env.BUMP_TYPE != 'patchVersion' }} | |
body: | | |
${{ steps.matching_release.outputs.body }} | |
${{ env.COMMIT_MSG }} | |