Release v2 #127
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: Release v2 | |
on: | |
workflow_dispatch: | |
inputs: | |
release_type: | |
description: "Release type" | |
type: choice | |
options: | |
- patch | |
- minor | |
- major | |
- provided | |
jobs: | |
get-artifact-id: | |
runs-on: ubuntu-latest | |
outputs: | |
artifact-id: ${{ steps.get-artifact-id.outputs.artifact-id }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Get artifactId | |
id: get-artifact-id | |
run: | | |
sudo apt-get install xmlstarlet | |
artifact_id=$(xmlstarlet sel -N pom=http://maven.apache.org/POM/4.0.0 -t -v "/pom:project/pom:artifactId" pom.xml) | |
echo "artifact-id=$artifact_id" >> "$GITHUB_OUTPUT" | |
get-current-version: | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.get-current-version.outputs.version }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Get current version | |
id: get-current-version | |
run: | | |
sudo apt-get install xmlstarlet | |
version=$(xmlstarlet sel -N pom=http://maven.apache.org/POM/4.0.0 -t -v "/pom:project/pom:version" pom.xml) | |
echo "version=$version" >> "$GITHUB_OUTPUT" | |
perform-tests: | |
# uses: ./.github/workflows/perform-tests.yml | |
runs-on: ubuntu-latest | |
environment: Test | |
concurrency: perform-tests | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'corretto' | |
cache: maven | |
# - name: Build with Maven | |
# env: | |
# REDDIT_SUBREDDIT: ${{ secrets.REDDIT_SUBREDDIT }} | |
# REDDIT_CLIENT_ID: ${{ secrets.REDDIT_CLIENT_ID }} | |
# REDDIT_CLIENT_SECRET: ${{ secrets.REDDIT_CLIENT_SECRET }} | |
# REDDIT_PASSWORD: ${{ secrets.REDDIT_PASSWORD }} | |
# REDDIT_USERNAME: ${{ secrets.REDDIT_USERNAME }} | |
# SPRING_JPA_HIBERNATE_DDL_AUTO: ${{ vars.SPRING_JPA_HIBERNATE_DDL_AUTO }} | |
# TELEGRAM_ADMIN_ID: ${{ secrets.TELEGRAM_ADMIN_ID }} | |
# TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} | |
# TELEGRAM_BOT_USERNAME: ${{ secrets.TELEGRAM_BOT_USERNAME }} | |
# TELEGRAM_CHANNEL_ID: ${{ secrets.TELEGRAM_CHANNEL_ID }} | |
# TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} | |
# TELEGRAM_SCHEDULE_POSTING_ENABLED: ${{ vars.TELEGRAM_SCHEDULE_POSTING_ENABLED }} | |
# run: mvn test | |
get-release-version: | |
runs-on: ubuntu-latest | |
needs: get-current-version | |
outputs: | |
version: ${{ steps.increment-patch-version.outputs.version | |
|| steps.increment-minor-version.outputs.version | |
|| steps.increment-major-version.outputs.version | |
|| needs.get-current-version.outputs.version }} | |
env: | |
VERSION: ${{ needs.get-current-version.outputs.version }} | |
steps: | |
- name: Split current version | |
id: split-current-version | |
run: | | |
version=$(echo "$VERSION" | grep -Po '^(\d+\.){2}\d+') | |
version=${version//./ } | |
echo "version=$version" >> "$GITHUB_OUTPUT" | |
- name: Fail on invalid current version | |
if: ${{ !steps.split-current-version.outputs.version }} | |
run: | | |
echo "::error::Unexpected artifact version found in pom.xml: $CURRENT_VERSION. Expected format: x.y.z" | |
exit 1 | |
- name: Increment patch version | |
id: increment-patch-version | |
if: github.event.inputs.release_type == 'patch' | |
env: | |
VERSION: ${{ steps.split-current-version.outputs.version }} | |
run: | | |
parts=($VERSION) | |
patch=$((parts[2] + 1)) | |
echo "version=${parts[0]}.${parts[1]}.$patch" >> "$GITHUB_OUTPUT" | |
- name: Increment minor version | |
id: increment-minor-version | |
if: github.event.inputs.release_type == 'minor' | |
env: | |
VERSION: ${{ steps.split-current-version.outputs.version }} | |
run: | | |
parts=($VERSION) | |
minor=$((parts[1] + 1)) | |
echo "version=${parts[0]}.$minor.0" >> "$GITHUB_OUTPUT" | |
- name: Increment major version | |
id: increment-major-version | |
if: github.event.inputs.release_type == 'major' | |
env: | |
VERSION: ${{ steps.split-current-version.outputs.version }} | |
run: | | |
parts=($VERSION) | |
major=$((parts[0] + 1)) | |
echo "version=$major.0.0" >> "$GITHUB_OUTPUT" | |
commit-new-version: | |
runs-on: ubuntu-latest | |
needs: | |
- perform-tests | |
- get-current-version | |
- get-release-version | |
env: | |
CURRENT_VERSION: ${{ needs.get-current-version.outputs.version }} | |
NEW_VERSION: ${{ needs.get-release-version.outputs.version }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
if: github.event.inputs.release_type != 'provided' | |
- name: Set new version | |
if: github.event.inputs.release_type != 'provided' | |
run: | | |
sudo apt-get install xmlstarlet | |
xmlstarlet ed -P -L -N pom=http://maven.apache.org/POM/4.0.0 -u "/pom:project/pom:version" -v "$NEW_VERSION" pom.xml | |
sed -i "s/$CURRENT_VERSION/$NEW_VERSION/g" README.md | |
- name: Commit changes | |
uses: tohgarashi/verified-commit@v2.x | |
if: github.event.inputs.release_type != 'provided' | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
files: | | |
pom.xml | |
README.md | |
commit-message: v${{ env.NEW_VERSION }} | |
build-jar: | |
runs-on: ubuntu-latest | |
needs: | |
- get-artifact-id | |
- get-release-version | |
- commit-new-version | |
outputs: | |
jar: ${{ env.JAR }} | |
env: | |
JAR: ${{ needs.get-artifact-id.outputs.artifact-id }}-${{ needs.get-release-version.outputs.version }}.jar | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'corretto' | |
cache: maven | |
- name: Build with maven | |
run: | | |
git pull | |
mvn package -Dmaven.test.skip | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ env.JAR }} | |
path: target/${{ env.JAR }} | |
deploy-to-remote: | |
runs-on: ubuntu-latest | |
environment: Prod | |
needs: | |
- build-jar | |
env: | |
USERNAME: ${{ secrets.SSH_USERNAME }} | |
PASSWORD: ${{ secrets.SSH_PASSWORD }} | |
HOST: ${{ secrets.SSH_HOST }} | |
DIR: ${{ secrets.SSH_DIR }} | |
JAR: ${{ needs.build-jar.outputs.jar }} | |
steps: | |
- name: Stop existing app | |
env: | |
CMD: | | |
cd ${{ env.DIR }} | |
if [[ -f application.pid ]] | |
then | |
echo "Application is running." | |
kill $(cat application.pid) | |
while [[ -f application.pid ]] | |
do | |
sleep 5 | |
done | |
else | |
echo "Application is not running." | |
fi | |
run: sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no -o LogLevel=quiet "$USERNAME@$HOST" "$CMD" | |
- name: Delete existing jar | |
env: | |
CMD: | | |
cd ${{ env.DIR }} | |
find . -name "*.jar" -delete | |
run: sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no -o LogLevel=quiet "$USERNAME@$HOST" "$CMD" | |
- name: Download artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: ${{ env.JAR }} | |
- name: Upload to remote | |
run: sshpass -p "$PASSWORD" scp -o StrictHostKeyChecking=no -o LogLevel=quiet "$JAR" "$USERNAME@$HOST:$DIR" | |
- name: Run the app | |
env: | |
CMD: | | |
cd ${{ env.DIR }} | |
java -jar ${{ env.JAR }} \ | |
--reddit.authors.blocked.by.default=${{ vars.REDDIT_AUTHORS_BLOCKED_BY_DEFAULT }} \ | |
--reddit.client.id=${{ secrets.REDDIT_CLIENT_ID }} \ | |
--reddit.client.secret=${{ secrets.REDDIT_CLIENT_SECRET }} \ | |
--reddit.password=${{ secrets.REDDIT_PASSWORD }} \ | |
--reddit.subreddit=${{ secrets.REDDIT_SUBREDDIT }} \ | |
--reddit.username=${{ secrets.REDDIT_USERNAME }} \ | |
--telegram.admin.id=${{ secrets.TELEGRAM_ADMIN_ID }} \ | |
--telegram.bot.token=${{ secrets.TELEGRAM_BOT_TOKEN }} \ | |
--telegram.bot.username=${{ secrets.TELEGRAM_BOT_USERNAME }} \ | |
--telegram.channel.id=${{ secrets.TELEGRAM_CHANNEL_ID }} \ | |
--telegram.chat.id=${{ secrets.TELEGRAM_CHAT_ID }} | |
run: nohup sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no -o LogLevel=quiet "$USERNAME@$HOST" "$CMD" & | |
draft-release: | |
runs-on: ubuntu-latest | |
needs: | |
- get-release-version | |
- build-jar | |
env: | |
JAR: ${{ needs.build-jar.outputs.jar }} | |
TAG: v${{ needs.get-release-version.outputs.version }} | |
steps: | |
- name: Download artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: ${{ env.JAR }} | |
- name: Draft release | |
id: draft-release | |
uses: shogo82148/actions-create-release@v1 | |
with: | |
tag_name: ${{ env.TAG }} | |
release_name: ${{ env.TAG }} | |
draft: true | |
- name: Upload Release Asset | |
uses: shogo82148/actions-upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.draft-release.outputs.upload_url }} | |
asset_path: ${{ env.JAR }} | |
asset_name: ${{ env.JAR }} | |
asset_content_type: application/java-archive |