Deploy #30
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: 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 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
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@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: contains(github.event.workflow_run.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' || false" | |
- name: Copy artifact to server | |
run: rsync -avzh --ignore-existing ROOT##*.war learnweb:${{ secrets.DEPLOY_PATH }}/ |