Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QA: Streamline build process for easier manual and automated tested #2397

Closed
wants to merge 10 commits into from
8 changes: 4 additions & 4 deletions .github/workflows/build-container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Configure Build X
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
Expand All @@ -32,7 +32,7 @@ jobs:
# Latest
- name: Build Latest
if: github.ref == 'refs/heads/master'
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
context: .
cache-from: type=gha
Expand All @@ -45,7 +45,7 @@ jobs:
# Release branch
- name: Build Branch
if: github.ref != 'refs/heads/master'
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
context: .
cache-from: type=gha
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/build-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build PR

on:
pull_request:
# pull_request_review:
# types: [submitted]

jobs:
build:
name: Build PR container
if: github.repository == 'xibosignage/xibo-cms'
# if: github.repository == 'xibosignage/xibo-cms' && github.event.review.state == 'APPROVED'
runs-on: ubuntu-22.04

steps:
- uses: octokit/[email protected]
id: build_pr
with:
route: POST /repos/{owner}/{repo}/dispatches
owner: xibosignageltd
repo: qa
pr_number: ${{ github.event.pull_request.number }}
sha: ${{ github.event.head.sha }}
issue_number: ${{ github.event.issue.number }}
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
12 changes: 9 additions & 3 deletions .github/workflows/build-tag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Configure Build X
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build Image
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
context: .
cache-from: type=gha
Expand All @@ -33,9 +36,11 @@ jobs:
build-args: GIT_COMMIT=${{ github.sha }}
push: true
load: false

- name: Pull Image
run: |
docker pull ghcr.io/xibosignage/xibo-cms:release-${GITHUB_REF##*/}

- name: Build archive
run: |
CONTAINER=$(docker create ghcr.io/xibosignage/xibo-cms:release-${GITHUB_REF##*/})
Expand All @@ -45,6 +50,7 @@ jobs:
zip -rq xibo-cms-${GITHUB_REF##*/}.zip xibo-cms-${GITHUB_REF##*/}
echo 'Added to archives.'
docker rm "$CONTAINER"

- name: Release
uses: softprops/action-gh-release@v1
with:
Expand Down
38 changes: 21 additions & 17 deletions .github/workflows/test-suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

# Step 3: Checkout the branch associated with the PR
- name: Checkout PR branch ${{ steps.comment-branch.outputs.head_ref }}
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ steps.comment-branch.outputs.head_sha }}

Expand Down Expand Up @@ -55,44 +55,46 @@ jobs:
echo "Comment does not match the expected format."
exit 1
fi
- name: Configure Build X
uses: docker/setup-buildx-action@v1
- name: Build
uses: docker/build-push-action@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
context: .
file: Dockerfile.ci
cache-from: type=gha
cache-to: type=gha,mode=max
tags: cms-web
build-args: GIT_COMMIT=${{ github.sha }}
push: false
load: true
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Pull
run: |
docker pull mysql:8
docker pull ghcr.io/xibosignage/xibo-xmr:latest
docker pull ghcr.io/xibosignageltd/qa:pr-${{ github.event.issue.number }}

- name: Run
run: |
docker run --name cms-db -e MYSQL_RANDOM_ROOT_PASSWORD=yes -e MYSQL_DATABASE=cms -e MYSQL_USER=cms -e MYSQL_PASSWORD=jenkins -d mysql:8
docker run --name cms-xmr -d ghcr.io/xibosignage/xibo-xmr:latest
docker run --name cms-web -e MYSQL_USER=cms -e MYSQL_PASSWORD=jenkins -e XIBO_DEV_MODE=true -e XMR_HOST=cms-xmr --link cms-db:db --link cms-xmr:50001 -d cms-web
# Run the CMS container, adjusting env for CI and copying back in PHP Unit
docker run --name cms-web -e MYSQL_USER=cms -e MYSQL_PASSWORD=jenkins -e XIBO_DEV_MODE=true -e XMR_HOST=cms-xmr -e CMS_USAGE_REPORT=false -e INSTALL_TYPE=ci -e MYSQL_BACKUP_ENABLED=false -v $(pwd)/tests:/var/www/cms/tests --link cms-db:db --link cms-xmr:50001 -d ghcr.io/xibosignageltd/qa:pr-${{ github.event.issue.number }}

- name: Wait for CMS
run: |
docker exec -t cms-web /bin/bash -c "/usr/local/bin/wait-for-command.sh -q -t 300 -c \"nc -z localhost 80\""
docker cp cms-web:/var/www/cms/web/settings.php web/settings.php
docker exec -t cms-web /bin/bash -c "chown -R www-data.www-data /var/www/cms"
docker exec --user www-data -t cms-web /bin/bash -c "cd /var/www/cms; /usr/bin/php bin/run.php 1"
sleep 5

- name: Seed Database
run: |
docker exec cms-db mysql -ucms -pjenkins cms -e "UPDATE setting SET value=\"6v4RduQhaw5Q\" WHERE setting = \"SERVER_KEY\" "
docker exec cms-db mysql -ucms -pjenkins cms -e "INSERT INTO task (name, class, status, isActive, configFile, options, schedule) VALUES ('Seed Database', '\\\\Xibo\\\\XTR\\\\SeedDatabaseTask', 2, 1, '/tasks/seed-database.task', '{}', '* * * * * *')"
docker exec --user www-data -t cms-web /bin/bash -c "cd /var/www/cms; /usr/bin/php bin/run.php \"Seed Database\""
sleep 5

- name: Run PHP Unit
run: |
docker exec --user www-data -t cms-web /bin/bash -c "cd /var/www/cms; php vendor/bin/phpunit --log-junit results.xml"

- name: Run Cypress
id: cypress
run: |
Expand All @@ -104,11 +106,13 @@ jobs:
docker run --ipc=host --name cms-cypress --link=cms-web:web -v $(pwd)/cypress.config.js:/app/cypress.config.js -v $(pwd)/cypress:/app/cypress ghcr.io/xibosignage/xibo-cms:cypress bash -c "CYPRESS_baseUrl=http://web /app/node_modules/.bin/cypress run --config screenshotsFolder=/app/cypress/results,video=false --spec \"$spec_content\" --reporter junit --reporter-options 'mochaFile=/app/cypress/results/results_cypress_[hash].xml,toConsole=true' && chown -R 1001:1001 /app/cypress/results && exit \${PIPESTATUS[0]};"
fi
continue-on-error: true

- name: Save Cypress test results as an artifact
uses: actions/upload-artifact@v3
with:
name: cypress-test-results
path: cypress/results

- name: Check Cypress exit code
run: |
if [[ ${{ steps.cypress.outcome }} == 'success' ]]; then
Expand All @@ -117,13 +121,14 @@ jobs:
echo "Cypress tests failed with exit code ${{ steps.cypress.exitCode }}"
exit 1
fi

# Step 5: Add a comment to the PR with the workflow result
- name: Add workflow result as comment on PR
uses: actions/github-script@v6
if: always()
with:
script: |
const name = '${{ github.workflow }}';
const name = '${{ github.workflow }}';
const url = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}';
const success = '${{ job.status }}' === 'success';
const body = `${name}: ${success ? 'succeeded ✅' : 'failed ❌'}\n${url}`;
Expand All @@ -142,5 +147,4 @@ jobs:
with:
sha: ${{ steps.comment-branch.outputs.head_sha }}
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}

status: ${{ job.status }}
Loading
Loading