Deploy #5
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 | |
- 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 -e "ssh bastion ssh" dev##*.war learnweb:${{ env.DEPLOY_PATH }}/ | |
# run: rsync -avzh --ignore-existing -e "ssh bastion ssh" dev##*.war learnweb:${{ env.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: Deploy | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.DEPLOY_HOST }} | |
username: ${{ secrets.DEPLOY_USERNAME }} | |
key: ${{ secrets.DEPLOY_PRIVATE_KEY }} | |
proxy_host: ${{ secrets.DEPLOY_JUMP_HOST }} | |
proxy_username: ${{ secrets.DEPLOY_JUMP_USERNAME }} | |
proxy_key: ${{ secrets.DEPLOY_PRIVATE_KEY }} | |
source: "ROOT##*.war" | |
target: ${{ secrets.DEPLOY_PATH }} | |
tar_exec: "tar --keep-old-files" |