Skip to content

Add unit tests

Add unit tests #797

name: Build Maven Project
on:
push:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
- name: Setup kubectl
uses: azure/setup-kubectl@v3
with:
version: 'latest'
- name: Create kubeconfig file
run: |
mkdir $HOME/.kube
echo "${{ secrets.KUBE_CONFIG_DATA }}" > $HOME/.kube/config
- name: Run Unit Test
run: |
cd react
npm install --include=dev
npm test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin'
server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml
server-username: MAVEN_USERNAME # env variable for username in deploy
server-password: MAVEN_PASSWORD # env variable for token in deploy
gpg-private-key: ${{ secrets.MVN_GPG_KEY }} # Value of the GPG private key to import
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
- name: Cache Maven repository
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2-
- name: Cache Node.js modules
uses: actions/cache@v3
with:
path: react/node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('react/package-lock.json') }}
restore-keys: ${{ runner.os }}-node-modules-
- name: Clone ant-media-server-parent
run: |
git clone --depth=1 https://github.com/ant-media/ant-media-server-parent.git
cd ant-media-server-parent
mvn clean install -DskipTests -Dmaven.javadoc.skip=true -Dgpg.skip=true --quiet
cd ..
- name: Clone Ant-Media-Server
run: |
CI_COMMIT_REF_NAME=$(echo $GITHUB_REF | cut -d'/' -f 3)
(if [ $(git ls-remote https://github.com/ant-media/Ant-Media-Server.git $CI_COMMIT_REF_NAME | wc -l) == "1" ];
then
echo "$CI_COMMIT_REF_NAME branch found in Ant-Media-Server";
git clone --depth=1 -b $CI_COMMIT_REF_NAME https://github.com/ant-media/Ant-Media-Server.git;
else
echo "$CI_COMMIT_REF_NAME branch not. Checking out master";
git clone --depth=1 https://github.com/ant-media/Ant-Media-Server.git;
fi)
cd Ant-Media-Server
mvn clean install -DskipTests -Dmaven.javadoc.skip=true -Dgpg.skip=true --quiet
cd ..
- name: Build React application for webinar
env:
CI: false
NODE_OPTIONS: '--max-old-space-size=4096'
run: |
cd react
mv .env.production .env.production.conferencing
mv .env.production.webinar .env.production
sed -i "s#^REACT_APP_TURN_SERVER_URL=.*#REACT_APP_TURN_SERVER_URL=\"turn:${{ secrets.STAGING_TURN_URL }}\"#" .env.production
sed -i "s#^REACT_APP_TURN_SERVER_USERNAME=.*#REACT_APP_TURN_SERVER_USERNAME=\"${{ secrets.STAGING_TURN_USERNAME }}\"#" .env.production
sed -i "s#^REACT_APP_TURN_SERVER_CREDENTIAL=.*#REACT_APP_TURN_SERVER_CREDENTIAL=\"${{ secrets.STAGING_TURN_PASSWORD }}\"#" .env.production
npm install
npm run build
cd ..
rm -r webapp/src/main/webapp/static/*
cp -a react/build/. webapp/src/main/webapp
- name: Build Maven project for webinar
run: |
cd webapp
mvn clean install -DskipTests -Dgpg.skip=true --quiet
ls -alh
ls -alh target/
cp target/*.war /tmp/circle-webinar.war
cd ..
- name: Build React application
env:
CI: false
NODE_OPTIONS: '--max-old-space-size=4096'
run: |
cd react
mv .env.production.conferencing .env.production
sed -i "s#^REACT_APP_TURN_SERVER_URL=.*#REACT_APP_TURN_SERVER_URL=\"turn:${{ secrets.STAGING_TURN_URL }}\"#" .env.production
sed -i "s#^REACT_APP_TURN_SERVER_USERNAME=.*#REACT_APP_TURN_SERVER_USERNAME=\"${{ secrets.STAGING_TURN_USERNAME }}\"#" .env.production
sed -i "s#^REACT_APP_TURN_SERVER_CREDENTIAL=.*#REACT_APP_TURN_SERVER_CREDENTIAL=\"${{ secrets.STAGING_TURN_PASSWORD }}\"#" .env.production
npm install
npm run build
cd ..
rm -r webapp/src/main/webapp/static/*
cp -a react/build/. webapp/src/main/webapp
- name: Build Maven project
run: |
cd webapp
mvn clean install -DskipTests -Dgpg.skip=true --quiet
ls -alh
ls -alh target/
cp target/*.war /tmp/circle-conferencing.war
cd ..
- name: Install Test Tool
run: |
sudo apt-get update
sudo apt-get install -y unzip iproute2 libva-drm2 libva-x11-2 libvdpau-dev ffmpeg
git clone https://gitlab.com/Ant-Media/webrtc-test.git
cd webrtc-test
./redeploy.sh
cp target/webrtc-load-test-tool-*.zip ../
cd ..
unzip webrtc-load-test-tool-*.zip
mkdir ~/test
mv webrtc-load-test ~/test
- name: Install Selenium
run: |
wget https://storage.googleapis.com/chrome-for-testing-public/130.0.6723.58/linux64/chromedriver-linux64.zip
unzip chromedriver-linux64.zip
sudo cp chromedriver-linux64/chromedriver /tmp
ls -al /tmp
pip3 install selenium==4.14
pip3 install requests
pip3 show selenium
pip3 install psutil
- name: Run Integration Test
run: |
cd test
python3 test_main.py ${{ secrets.STAGING_SERVER_URL }} ${{ secrets.USER_NAME }} ${{ secrets.PASSWORD }} /tmp/circle-conferencing.war false
- name: Run Integration Test for webinar
run: |
cd test
python3 test_main.py ${{ secrets.STAGING_SERVER_URL }} ${{ secrets.USER_NAME }} ${{ secrets.PASSWORD }} /tmp/circle-webinar.war true
- name: Copy Logs From Pods
if: always()
run: |
for pod in $(kubectl -n circle get pods | grep "ant-media-server" | awk '{print $1}'); do
node_ip=$(kubectl -n circle get pods -o wide | grep "$pod" | awk '{print $6}')
kubectl -n circle cp $pod:/usr/local/antmedia/log/ant-media-server.log /tmp/ant-media-server-$node_ip.log
kubectl -n circle cp $pod:/usr/local/antmedia/log/antmedia-error.log /tmp/antmedia-error-$node_ip.log
done
- name: Upload PNG files as artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: screenshots
path: ${{ github.workspace }}/test/**/*.png
- name: Upload log files as artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: logs
path: /tmp/*.log
- name: Upload war files as artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: wars
path: /tmp/*.war
- name: Publish to Maven Central
if: github.ref == 'refs/heads/main'
run: |
cd webapp
ls -alh
ls -alh target/
mvn -e deploy -DskipTests --quiet --settings ../mvn-settings.xml
env:
MAVEN_USERNAME: ${{ secrets.MVN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MVN_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MVN_GPG_PASSPHRASE }}
deploy:
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v3
- name: Get versions data from repo
run: wget -O maven-metadata.xml https://oss.sonatype.org/service/local/repositories/snapshots/content/io/antmedia/ant-media-server/maven-metadata.xml
- name: Install jq
run: sudo apt-get install jq -y
- name: Download war File
run: |
export LATEST_SNAPSHOT=$(cat maven-metadata.xml | grep "<version>" | tail -n 1 | xargs | grep -oP "(?<=<version>).*?(?=</version>)")
echo $LATEST_SNAPSHOT
wget -O ConferenceCall.war "https://oss.sonatype.org/service/local/artifact/maven/redirect?r=snapshots&g=io.antmedia.webrtc&a=ConferenceCall&v=${LATEST_SNAPSHOT}&e=war"
ls -al
if [ ! -f ConferenceCall.war ]; then
echo "War file not found."
exit 1
fi
- name: Login to server
run: |
response=$(curl -X POST -H "Accept: Application/json" -H "Content-Type: application/json" ${{ secrets.STAGING_SERVER_URL }}/rest/v2/users/authenticate -d '{"email":"${{ secrets.USER_NAME }}","password":"${{ secrets.PASSWORD }}"}' -c cookie.txt)
success=$(echo $response | jq -r '.success')
if [ "$success" != "true" ]; then
echo "Login failed"
exit 1
fi
- name: Check if Conference App Exists
run: |
response=$(curl -s -H "Accept: Application/json" -H "Content-Type: application/json" "${{ secrets.STAGING_SERVER_URL }}/rest/v2/applications" -b cookie.txt)
echo $response | jq .
app_exists=$(echo $response | jq -r '.applications | index("Conference")')
if [ "$app_exists" != "null" ]; then
echo "App exists, proceeding to delete it."
response=$(curl -s -X DELETE -H "Accept: Application/json" -H "Content-Type: application/json" "${{ secrets.STAGING_SERVER_URL }}/rest/v2/applications/Conference" -b cookie.txt)
success=$(echo $response | jq -r '.success')
if [ "$success" != "true" ]; then
echo "Conference app deletion failed"
exit 1
fi
sleep 10
else
echo "App does not exist, proceeding to create a new one."
fi
- name: Create New App
run: |
export WAR_FILE_NAME="ConferenceCall.war"
response=$(curl -X PUT -H "Accept: Application/json" -H "Content-Type: multipart/form-data" -F "file=@./$WAR_FILE_NAME" "${{ secrets.STAGING_SERVER_URL }}/rest/v2/applications/Conference" -b cookie.txt)
sleep 5
success=$(echo $response | jq -r '.success')
if [ "$success" != "true" ]; then
echo "Conference app creation is failed"
exit 1
fi
sleep 10
- name: Update Turn Settings
run: |
curl "${{ secrets.STAGING_SERVER_URL }}/rest/v2/applications/settings/Conference" -b cookie.txt -o settings.json
jq '.stunServerURI = "turn:${{ secrets.STAGING_TURN_URL }}" | .turnServerUsername = "${{ secrets.STAGING_TURN_USERNAME }}" | .turnServerCredential = "${{ secrets.STAGING_TURN_PASSWORD }}"' settings.json > updated_settings.json
response=$(curl -X POST -H "Accept: Application/json" -H "Content-Type: application/json" -d @updated_settings.json -b cookie.txt "${{ secrets.STAGING_SERVER_URL }}/rest/v2/applications/settings/Conference")
success=$(echo $response | jq -r '.success')
if [ "$success" != "true" ]; then
echo "Importing setting is failed."
exit 1
fi