Skip to content

Commit

Permalink
ci: add deploy workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
astappiev committed Oct 6, 2023
1 parent 2ab3bf8 commit 5457806
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 129 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
100 changes: 100 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
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 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
4 changes: 2 additions & 2 deletions src/test/java/de/l3s/util/ProfileImageHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class ProfileImageHelperTest {

@Test
@Disabled("Remote host terminated the handshake on GitLab :(")
@Disabled("Remote HTTP requests should be disabled on CI")
void getGravatarAvatar() {
ImmutableTriple<String, String, InputStream> gravatar = ProfileImageHelper.getGravatarAvatar("205e460b479e2e5b48aec07710c08d50");

Expand All @@ -22,7 +22,7 @@ void getGravatarAvatar() {
}

@Test
@Disabled("Remote host terminated the handshake on GitLab :(")
@Disabled("Remote HTTP requests should be disabled on CI")
void getGravatarAvatarMissing() {
ImmutableTriple<String, String, InputStream> gravatar = ProfileImageHelper.getGravatarAvatar("00000000000000000000000000000000");

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/de/l3s/util/UrlHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void removeTrailingSlash() {
}

@Test
@Disabled("because it makes real connection which is prohibited by firewall on GitLab Runner")
@Disabled("Remote HTTP requests should be disabled on CI")
void validateUrl() {
assertEquals("https://en.wikipedia.org/wiki/Hamburg", UrlHelper.validateUrl("https://en.wikipedia.org/wiki/Hamburg"));
assertEquals("https://waps.io/live/https://en.wikipedia.org/wiki/Hamburg", UrlHelper.validateUrl("https%3A%2F%2Fwaps.io%2Flive%2Fhttps%3A%2F%2Fen.wikipedia.org%2Fwiki%2FHamburg"));
Expand Down

0 comments on commit 5457806

Please sign in to comment.