Skip to content

Deploy Dev

Deploy Dev #246

Workflow file for this run

name: Deploy Dev
on:
workflow_run:
workflows: [ CI ]
types: [ completed ]
branches: [ main ]
env:
ARTIFACT_NAME: learnweb-war
jobs:
build:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- uses: actions/checkout@v5
- uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '25'
cache: 'maven'
- uses: actions/setup-node@v6
with:
node-version-file: 'package.json'
cache: 'npm'
- run: npm ci
- run: npm run build
- run: mvn --batch-mode -P prod,!local -Dmaven.test.skip=true -Drevision=dev-${{ github.sha }} install
- uses: actions/upload-artifact@v5
with:
name: ${{ env.ARTIFACT_NAME }}
path: target/Learnweb.war
if-no-files-found: error
deploy:
environment: staging
runs-on: ubuntu-latest
needs: [ build ]
env:
DEPLOY_ROOT: ~/stacks/learnweb_dev/webapps
DEPLOY_NAME: dev
steps:
- uses: appleboy/ssh-action@v1
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 }}
script: |
#!/bin/bash
set -e
cd ${{ env.DEPLOY_ROOT }}
TEMP_DIR=$(mktemp -d)
echo "Getting artifact from workflow ${{ github.run_id }}"
ARTIFACT_ID=$(curl --no-progress-meter --fail-with-body \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}" \
"https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts" | \
jq -r '.artifacts[] | select(.name=="${{ env.ARTIFACT_NAME }}") | .id')
echo "Downloading artifact $ARTIFACT_ID"
curl --no-progress-meter --fail-with-body -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}" \
"https://api.github.com/repos/${{ github.repository }}/actions/artifacts/${ARTIFACT_ID}/zip" \
-o "${TEMP_DIR}/artifact.zip"
unzip -q "${TEMP_DIR}/artifact.zip" -d "${TEMP_DIR}"
mv "${TEMP_DIR}/Learnweb.war" "${{ env.DEPLOY_NAME }}.war"
echo "Artifact deployed as ${{ env.DEPLOY_NAME }}"
rm -rf "${TEMP_DIR}"