Updated yml with docker #21
This file contains hidden or 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: Run & Deploy Reports to GitHub Pages | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
run-tests: | |
timeout-minutes: 60 | |
name: Run Tests | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout the repository | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
# Step 2: Set up Docker | |
- name: Set up Docker | |
uses: docker/setup-buildx-action@v2 | |
# Step 3: Start ChainTest service with Docker Compose | |
- name: Start Docker Services | |
run: | | |
docker compose -f .github/workflows/docker-compose-h2.yml up -d | |
sleep 15 # Wait for the service to initialize | |
# Step 4: Verify ChainTest service is running | |
- name: Verify ChainTest Service is Running | |
run: curl --fail http://localhost:80/ || exit 1 | |
# Step 5: Set up Java (Temurin 17) | |
- name: Set up Java | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
# Step 6: Cache Maven packages for faster builds | |
- name: Cache Maven Dependencies | |
uses: actions/cache@v4 | |
with: | |
path: ~/.m2 | |
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} | |
restore-keys: | | |
${{ runner.os }}-m2 | |
# Step 7: Install project dependencies | |
- name: Install Dependencies | |
run: mvn install -DskipTests | |
# Step 8: Set up Xvfb (for GUI-based tests, e.g., Selenium) | |
- name: Set up Xvfb | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y xvfb | |
Xvfb :99 & | |
export DISPLAY=:99 | |
# Step 9: Run Selenium Tests | |
- name: Run Selenium Tests | |
run: mvn test | |
env: | |
DISPLAY: :99 | |
# Step 10: Archive Test Reports | |
- name: Archive Test Reports | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Reports | |
path: target/chaintest/ # Adjust this path if your reports are elsewhere | |
retention-days: 7 | |
# Step 11: Stop Docker Services | |
- name: Stop Docker Services | |
if: always() | |
run: docker compose -f .github/workflows/docker-compose-h2.yml down | |
deploy-pages: | |
name: Deploy Reports to GitHub Pages | |
runs-on: ubuntu-latest | |
if: ${{ always() }} # Runs even if previous job fails | |
needs: run-tests | |
permissions: | |
contents: write | |
steps: | |
# Step 1: Checkout the repository | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
# Step 2: Download archived test reports | |
- name: Download Test Reports | |
uses: actions/download-artifact@v4 | |
with: | |
name: Reports | |
path: ./target/chaintest | |
# Step 3: Prepare Reports for Deployment | |
- name: Prepare Reports | |
run: | | |
mkdir -p public | |
cp -R target/chaintest/* public/ | |
mv public/Index.html public/index.html | |
# Step 4: Deploy to GitHub Pages | |
- name: Deploy to GitHub Pages | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GH_TOKEN }} | |
publish_dir: ./public | |
force_orphan: true |