Skip to content

Merge pull request #42 from TooManyFiles/issue41 #20

Merge pull request #42 from TooManyFiles/issue41

Merge pull request #42 from TooManyFiles/issue41 #20

Workflow file for this run

name: Build and Push Docker Image
on:
push:
tags:
- 'v*.*.*' # Triggers on version tags
workflow_dispatch: # Allows manual triggering
jobs:
test:
runs-on: ubuntu-latest
services:
chrome:
image: selenium/standalone-chrome
options: >-
--shm-size 2g
ports:
- 4444:4444
http_server:
image: nginx:alpine
ports:
- 5500:80
volumes:
- ${{ github.workspace }}:/usr/share/nginx/html # Mount the code directory
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
submodules: true # This ensures that submodules are also checked out
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8' # Specify your desired Python version
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r ./devtools/screenshots/requirements.txt
- name: Wait for server to start
run: |
# Wait for the server to respond
curl -s http://localhost:5500/
for i in {1..10}; do
if curl -s http://localhost:5500/ > /dev/null; then
echo "Server is up!"
break
fi
echo "Waiting for server..."
sleep 5 # Wait 5 seconds before trying again
done
- name: Run tests
run: |
cd ./devtools/screenshots
python main.py
- name: Add and commit screenshots
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add public/screenshots/*
git add manifest.json
git commit -m "Add screenshots from headless browser tests" || echo "No changes to commit"
git push origin HEAD:main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Use the GitHub token for authentication
build:
runs-on: ubuntu-latest
needs: test # Ensure this job waits for the previous job to finish
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Extract version from tag and Extract major, minor, and patch versions
id: version_parts
run: |
VERSION=${GITHUB_REF#refs/tags/}
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
IFS='.' read -r major minor patch <<< "${VERSION#v}"
echo "MAJOR=${major}" >> $GITHUB_ENV
echo "MINOR=${minor}" >> $GITHUB_ENV
echo "PATCH=${patch}" >> $GITHUB_ENV
- name: Build Docker Image
run: |
docker build -t ghcr.io/toomanyfiles/tmf-timetable-frontend:${{ env.VERSION }} \
-t ghcr.io/toomanyfiles/tmf-timetable-frontend:v${{ env.MAJOR }} \
-t ghcr.io/toomanyfiles/tmf-timetable-frontend:v${{ env.MAJOR }}.${{ env.MINOR }} \
-t ghcr.io/toomanyfiles/tmf-timetable-frontend:latest .
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push Docker Image with version, minor, major, and latest tags
run: |
docker push ghcr.io/toomanyfiles/tmf-timetable-frontend:${{ env.VERSION }}
docker push ghcr.io/toomanyfiles/tmf-timetable-frontend:v${{ env.MAJOR }}
docker push ghcr.io/toomanyfiles/tmf-timetable-frontend:v${{ env.MAJOR }}.${{ env.MINOR }}
docker push ghcr.io/toomanyfiles/tmf-timetable-frontend:latest