diff --git a/.github/workflows/continuous.integration.yml b/.github/workflows/continuous.integration.yml new file mode 100644 index 0000000..1092d1a --- /dev/null +++ b/.github/workflows/continuous.integration.yml @@ -0,0 +1,56 @@ +name: Run Checks on PR + +on: + pull_request: + branches: + - main + +permissions: + actions: write + checks: write + contents: read + security-events: write + pull-requests: write + +env: + CI: true + SITE_DIR: site + TETRIS_APP_HOST: "127.0.0.1" + TETRIS_APP_PORT: "8080" + TETRIS_APP_PATH: "github-devsecops-fundamentals" + +jobs: + quality-checks: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-python@v4 + with: + python-version: 3.12 + - uses: actions/setup-node@v3 + with: + node-version: 20 + + - name: Install Dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.ci.txt + npm ci + # Install browsers for running functional tests + npx playwright install --with-deps chromium + + - name: Build + run: | + python -m mkdocs build --clean --strict --verbose --site-dir '${{ env.SITE_DIR }}' + + - name: Functional Test + run: npx playwright test + + - name: Upload Functional Test Report + uses: actions/upload-artifact@v3 + if: always() + with: + name: playwright-report + path: playwright-report/ + retention-days: 30 diff --git a/docs/.tetris.game/LICENSE b/docs/tetris.game/LICENSE similarity index 100% rename from docs/.tetris.game/LICENSE rename to docs/tetris.game/LICENSE diff --git a/docs/.tetris.game/README.txt b/docs/tetris.game/README.txt similarity index 100% rename from docs/.tetris.game/README.txt rename to docs/tetris.game/README.txt diff --git a/docs/.tetris.game/app.js b/docs/tetris.game/app.js similarity index 100% rename from docs/.tetris.game/app.js rename to docs/tetris.game/app.js diff --git a/docs/.tetris.game/app.test.js b/docs/tetris.game/app.test.js similarity index 100% rename from docs/.tetris.game/app.test.js rename to docs/tetris.game/app.test.js diff --git a/docs/.tetris.game/index.html b/docs/tetris.game/index.html similarity index 100% rename from docs/.tetris.game/index.html rename to docs/tetris.game/index.html diff --git a/docs/.tetris.game/stats.js b/docs/tetris.game/stats.js similarity index 100% rename from docs/.tetris.game/stats.js rename to docs/tetris.game/stats.js diff --git a/docs/.tetris.game/style.css b/docs/tetris.game/style.css similarity index 100% rename from docs/.tetris.game/style.css rename to docs/tetris.game/style.css diff --git a/docs/.tetris.game/texture.jpg b/docs/tetris.game/texture.jpg similarity index 100% rename from docs/.tetris.game/texture.jpg rename to docs/tetris.game/texture.jpg diff --git a/mkdocs.yml b/mkdocs.yml index b12b921..86b9ce4 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -166,4 +166,4 @@ nav: - exercises/03.automate.release/02.md - ✨ Recap: - exercises/recap/index.md - - Tetris Game: tetris.game/index.html + - Tetris Game: tetris.game/index.html \ No newline at end of file diff --git a/tests/tetris.spec.js b/tests/tetris.spec.js new file mode 100644 index 0000000..7617572 --- /dev/null +++ b/tests/tetris.spec.js @@ -0,0 +1,26 @@ +import { test, expect } from "@playwright/test"; + +test("Tetris Game", async ({ page }) => { + const { TETRIS_APP_HOST, TETRIS_APP_PORT, TETRIS_APP_PATH } = process.env; + + // should be similar to http://127.0.0.1:8080/github-devsecops-fundamentals/ + console.log( + `http://${TETRIS_APP_HOST}:${TETRIS_APP_PORT}/${TETRIS_APP_PATH}` + ); + await page.goto( + `http://${TETRIS_APP_HOST}:${TETRIS_APP_PORT}/${TETRIS_APP_PATH}` + ); + + await page.getByRole("link", { name: "Tetris Game" }).click(); + await expect(page.getByText("score 00000")).toBeVisible(); + await expect(page.getByText("rows 0")).toBeVisible(); + await expect(page.locator("#upcoming")).toBeVisible(); + await expect( + page.getByRole("link", { name: "Press Space to Play." }) + ).toBeVisible(); + + await page.getByRole("link", { name: "Press Space to Play." }).click(); + await expect(page.getByText("score 00000")).not.toBeVisible({ + timeout: 0.5 * 60 * 1000, + }); +});