Skip to content

Commit

Permalink
ci: add deploy to staging
Browse files Browse the repository at this point in the history
  • Loading branch information
astappiev committed Oct 6, 2023
1 parent 2ab3bf8 commit 76e53fb
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 126 deletions.
39 changes: 16 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
name: test
name: CI

on:
push:
branches:
- main

env:
MVN: mvn --show-version --batch-mode --quiet
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
pull_request:

jobs:
styles:
Expand All @@ -22,8 +17,11 @@ jobs:
- run: npm run lint:scss --silent
- run: npm run lint:js --silent

lint:
java:
runs-on: ubuntu-latest
env:
MVN: mvn --batch-mode
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
Expand All @@ -32,19 +30,14 @@ jobs:
distribution: 'temurin'
cache: 'maven'
server-id: github-l3s-learnweb
- run: $MVN checkstyle:check
- run: $MVN compile spotbugs:check

test:
runs-on: ubuntu-latest
needs:
- lint
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 test
- name: Run Checkstyle check
run: $MVN checkstyle:check

- name: Run SpotBugs check
if: success() || failure()
run: $MVN compile spotbugs:check

- name: Run tests
if: success() || failure()
run: $MVN --show-version test
103 changes: 103 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
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: Check if artifact exists
run: ssh learnweb test -f "${{ secrets.DEPLOY_PATH }}/dev##${{ needs.build.outputs.version }}.war" && exit 1

- 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 }}/
86 changes: 0 additions & 86 deletions .gitlab-ci.yml

This file was deleted.

19 changes: 2 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -475,21 +475,6 @@
</webResources>
</configuration>
</plugin>
<!-- Used to deploy application to Tomcat instance -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://learnweb.l3s.uni-hannover.de:8100/manager/text</url>
<!--suppress UnresolvedMavenProperty -->
<username>${env.LEARNWEB_TOMCAT_USERNAME}</username>
<!--suppress UnresolvedMavenProperty -->
<password>${env.LEARNWEB_TOMCAT_PASSWORD}</password>
<!--suppress UnresolvedMavenProperty -->
<path>/${path}##${project.version}</path>
</configuration>
</plugin>
<!-- Can be used to run the application without Tomcat server -->
<plugin>
<groupId>org.eclipse.jetty</groupId>
Expand Down Expand Up @@ -553,7 +538,7 @@
<configuration>
<rules>
<requireMavenVersion>
<version>[3.6,)</version>
<version>[3.8,)</version>
</requireMavenVersion>
<requireJavaVersion>
<version>[17,)</version>
Expand Down Expand Up @@ -584,7 +569,7 @@
</resources>
</build>
</profile>
<!-- Used on GitLab when creating package to deploy -->
<!-- Used when creating packages to deploy -->
<profile>
<id>prod</id>
<properties>
Expand Down

0 comments on commit 76e53fb

Please sign in to comment.