Skip to content

Deploy

Deploy #15

Workflow file for this run

name: Deploy
on:
workflow_run:
workflows: [ CI ]
types: [ completed ]
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
outputs:
version: ${{ steps.vars.outputs.version }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'
server-id: github-l3s-learnweb
- run: mvn --quiet -P prod,!local -Dmaven.test.skip=true install
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
- name: Read version
id: vars
run: echo "version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_OUTPUT
- uses: actions/upload-artifact@v3
with:
name: learnweb-war
path: target/Learnweb.war
if-no-files-found: error
deploy-dev:
runs-on: ubuntu-latest
needs: [ build ]
steps:
- uses: actions/download-artifact@v3
with:
name: learnweb-war
- name: Rename artifact
run: mv Learnweb.war dev##${{ needs.build.outputs.version }}.war
- name: Install SSH keys
uses: shimataro/ssh-key-action@v2
with:
name: id_ed25519
key: ${{ secrets.DEPLOY_PRIVATE_KEY }}
known_hosts: ${{ secrets.DEPLOY_KNOWN_HOSTS }}
config: |
Host bastion
HostName ${{ secrets.DEPLOY_JUMP_HOST }}
User ${{ secrets.DEPLOY_JUMP_USERNAME }}
Host learnweb
HostName ${{ secrets.DEPLOY_HOST }}
User ${{ secrets.DEPLOY_USERNAME }}
ProxyJump bastion
- name: Copy artifact to server
run: rsync -avzh dev##*.war learnweb:${{ secrets.DEPLOY_PATH }}/
deploy-prod:
runs-on: ubuntu-latest
if: startsWith(github.event.head_commit.message, 'chore') && endsWith(github.event.head_commit.message, 'version release')
needs: [ build ]
steps:
- uses: actions/download-artifact@v3
with:
name: learnweb-war
- name: Rename artifact
run: mv Learnweb.war ROOT##${{ needs.build.outputs.version }}.war
- name: Install SSH keys
uses: shimataro/ssh-key-action@v2
with:
name: id_ed25519
key: ${{ secrets.DEPLOY_PRIVATE_KEY }}
known_hosts: ${{ secrets.DEPLOY_KNOWN_HOSTS }}
config: |
Host bastion
HostName ${{ secrets.DEPLOY_JUMP_HOST }}
User ${{ secrets.DEPLOY_JUMP_USERNAME }}
Host learnweb
HostName ${{ secrets.DEPLOY_HOST }}
User ${{ secrets.DEPLOY_USERNAME }}
ProxyJump bastion
- name: Check if artifact exists
run: ssh learnweb test -f "${{ secrets.DEPLOY_PATH }}/ROOT##${{ needs.build.outputs.version }}.war" && exit 1
- name: Copy artifact to server
run: rsync -avzh --ignore-existing ROOT##*.war learnweb:${{ secrets.DEPLOY_PATH }}/