Skip to content

Deploy

Deploy #172

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@v4
with:
distribution: 'temurin'
java-version: '21'
cache: 'maven'
- uses: actions/setup-node@v4
with:
node-version-file: 'package.json'
cache: 'npm'
- run: npm ci
- run: npm run build
- 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@v4
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@v4
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: contains(github.event.workflow_run.head_commit.message, 'version release')
needs: [ build ]
steps:
- uses: actions/download-artifact@v4
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' || false"
- name: Copy artifact to server
run: rsync -avzh --ignore-existing ROOT##*.war learnweb:${{ secrets.DEPLOY_PATH }}/