Skip to content

Commit

Permalink
QA: offload PR container building to another repository.
Browse files Browse the repository at this point in the history
  • Loading branch information
dasgarner committed Feb 29, 2024
1 parent 7e39242 commit 91243f1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 53 deletions.
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
52 changes: 11 additions & 41 deletions .github/workflows/build-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,18 @@ jobs:
build:
name: Build PR container
if: github.repository == 'xibosignage/xibo-cms'
# if: github.repository == 'xibosignage/xibo-cms' && github.event.review.state == 'APPROVED'
# if: github.repository == 'xibosignage/xibo-cms' && github.event.review.state == 'APPROVED'
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write

steps:
- name: Checkout
uses: actions/checkout@v4
- uses: octokit/[email protected]
id: build_pr
with:
fetch-depth: 1

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

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

- name: Build Container
uses: docker/build-push-action@v5
with:
context: .
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ghcr.io/${{ github.actor }}/xibo-cms:pr-${{ github.event.pull_request.number }}
build-args: GIT_COMMIT=${{ github.event.head.sha }}
push: true
load: false

- name: Update PR with Package name
uses: actions/github-script@v6
with:
script: |
const body = 'Image ready at ghcr.io/${{ github.actor }}/xibo-cms:pr-${{ github.event.pull_request.number }}';
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
})
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
25 changes: 20 additions & 5 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,33 +55,46 @@ jobs:
echo "Comment does not match the expected format."
exit 1
fi
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
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/xibosignage/xibo-cms:test-${{ github.event.issue.number }}
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
# 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/xibosignage/xibo-cms:test-${{ github.event.issue.number }}
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 @@ -93,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 @@ -106,6 +121,7 @@ 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
Expand All @@ -131,5 +147,4 @@ jobs:
with:
sha: ${{ steps.comment-branch.outputs.head_sha }}
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}

status: ${{ job.status }}

0 comments on commit 91243f1

Please sign in to comment.