From f28115afc3d71f13975cf15e685cff23549a9281 Mon Sep 17 00:00:00 2001 From: Graham Steffaniak <42989099+gtsteffaniak@users.noreply.github.com> Date: Mon, 17 Feb 2025 11:51:16 -0500 Subject: [PATCH] updated workflows (#377) --- .github/workflows/create-dev-branch.yaml | 58 +++++++++ .github/workflows/main.yaml | 4 +- .github/workflows/pr.yaml | 54 ++++++++- .github/workflows/promote-beta-to-stable.yaml | 110 ++++++++++++++++++ .github/workflows/promote-dev-to-beta.yaml | 99 ++++++++++++++++ .github/workflows/release_beta.yaml | 51 +------- .github/workflows/release_dev.yaml | 6 +- .github/workflows/release_stable.yaml | 47 +------- .github/workflows/tag.yaml | 47 ++++++++ _docker/Dockerfile.playwright-noauth | 8 ++ _docker/Dockerfile.playwright-proxy | 10 ++ ...aywright => Dockerfile.playwright-regular} | 4 +- _docker/docker-compose.yaml | 6 +- _docker/src/config.yaml | 8 -- _docker/src/noauth/backend/config.yaml | 15 +++ .../src/noauth/frontend/playwright.config.ts | 47 ++++++++ _docker/src/proxy/backend/config.yaml | 35 ++++++ _docker/src/{ => proxy/backend}/default.conf | 2 +- .../src/proxy/frontend/playwright.config.ts | 47 ++++++++ .../src/regular/backend/config.yaml | 3 - .../regular/frontend}/playwright.config.ts | 0 frontend/tests-proxy/preview.spec.ts | 55 +++++++++ makefile | 6 +- 23 files changed, 608 insertions(+), 114 deletions(-) create mode 100644 .github/workflows/create-dev-branch.yaml create mode 100644 .github/workflows/promote-beta-to-stable.yaml create mode 100644 .github/workflows/promote-dev-to-beta.yaml create mode 100644 _docker/Dockerfile.playwright-noauth create mode 100644 _docker/Dockerfile.playwright-proxy rename _docker/{Dockerfile.playwright => Dockerfile.playwright-regular} (53%) delete mode 100644 _docker/src/config.yaml create mode 100644 _docker/src/noauth/backend/config.yaml create mode 100644 _docker/src/noauth/frontend/playwright.config.ts create mode 100644 _docker/src/proxy/backend/config.yaml rename _docker/src/{ => proxy/backend}/default.conf (88%) create mode 100644 _docker/src/proxy/frontend/playwright.config.ts rename backend/filebrowser-playwright.yaml => _docker/src/regular/backend/config.yaml (92%) rename {frontend => _docker/src/regular/frontend}/playwright.config.ts (100%) create mode 100644 frontend/tests-proxy/preview.spec.ts diff --git a/.github/workflows/create-dev-branch.yaml b/.github/workflows/create-dev-branch.yaml new file mode 100644 index 00000000..f983d7bd --- /dev/null +++ b/.github/workflows/create-dev-branch.yaml @@ -0,0 +1,58 @@ +name: Create Dev Version + +on: + workflow_dispatch: + inputs: + version: + description: "Version to create (format: 0.0.0)" + required: true + type: string + +jobs: + create-dev-branch: + name: Create Dev Branch + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v4 + with: + token: ${{ secrets.PAT }} # Uses the Personal Access Token + + - name: Validate version format + id: validate_version + run: | + VERSION="${{ github.event.inputs.version }}" + if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "❌ ERROR: Version must be in '0.0.0' format." + exit 1 + fi + echo "✅ Version format validated: $VERSION" + + - name: Check if branch already exists + id: check_branch + run: | + VERSION="${{ github.event.inputs.version }}" + DEV_BRANCH="dev/v$VERSION" + + if git ls-remote --exit-code origin "$DEV_BRANCH"; then + echo "❌ ERROR: Branch '$DEV_BRANCH' already exists!" + exit 1 + fi + echo "✅ Branch '$DEV_BRANCH' does not exist." + + - name: Create and push new dev branch + run: | + VERSION="${{ github.event.inputs.version }}" + DEV_BRANCH="dev/v$VERSION" + + # Fetch latest changes + git fetch origin main + + # Create new branch from main + git checkout -b "$DEV_BRANCH" origin/main + + # Push branch to remote + git push origin "$DEV_BRANCH" + + echo "✅ Successfully created branch '$DEV_BRANCH'!" diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 477117eb..f1cf4402 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -6,7 +6,7 @@ on: - "main" jobs: - test_frontend: + test_playwright: name: Test Playwright runs-on: ubuntu-latest steps: @@ -31,7 +31,7 @@ jobs: file: ./_docker/Dockerfile.playwright push: false push_latest_to_registry: - needs: [ test_frontend ] + needs: [ test_playwright ] name: Push latest runs-on: ubuntu-latest steps: diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 93a4ff78..24f42259 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -8,7 +8,7 @@ on: - "stable/v[0-9]+.[0-9]+.[0-9]+" jobs: - test_frontend: + test_playwright: name: Test Playwright runs-on: ubuntu-latest steps: @@ -30,7 +30,55 @@ jobs: uses: docker/build-push-action@v6 with: context: . - file: ./_docker/Dockerfile.playwright + file: ./_docker/Dockerfile.playwright-regular + push: false + test_playwright_proxy: + name: Test Playwright - regular + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3.0.0 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.0.0 + - uses: actions/setup-node@v4 + - working-directory: frontend + run: npm i && npm run build + - uses: actions/setup-go@v5 + with: + go-version: 'stable' + - working-directory: backend + run: go build -o filebrowser . + - name: Build + uses: docker/build-push-action@v6 + with: + context: . + file: ./_docker/Dockerfile.playwright-proxy + push: false + test_playwright_noauth: + name: Test Playwright - regular + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3.0.0 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.0.0 + - uses: actions/setup-node@v4 + - working-directory: frontend + run: npm i && npm run build + - uses: actions/setup-go@v5 + with: + go-version: 'stable' + - working-directory: backend + run: go build -o filebrowser . + - name: Build + uses: docker/build-push-action@v6 + with: + context: . + file: ./_docker/Dockerfile.playwright-noauth push: false push_pr_to_registry: name: Push PR @@ -57,7 +105,7 @@ jobs: with: context: . file: ./_docker/Dockerfile - push: true + push: false # Do not push the image for now tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} build-args: | diff --git a/.github/workflows/promote-beta-to-stable.yaml b/.github/workflows/promote-beta-to-stable.yaml new file mode 100644 index 00000000..9794fc3f --- /dev/null +++ b/.github/workflows/promote-beta-to-stable.yaml @@ -0,0 +1,110 @@ +name: Promote Beta to Stable + +on: + workflow_dispatch: + inputs: + version: + description: "Version to promote (format: 0.0.0)" + required: true + type: string + +jobs: + promote-beta-to-stable: + name: Promote Beta to Stable + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v4 + with: + token: ${{ secrets.PAT }} # Uses Personal Access Token for branch operations + + - name: Validate version format + id: validate_version + run: | + VERSION="${{ github.event.inputs.version }}" + if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "❌ ERROR: Version must be in '0.0.0' format." + exit 1 + fi + echo "✅ Version format validated: $VERSION" + + - name: Check if beta branch exists + id: check_beta_branch + run: | + VERSION="${{ github.event.inputs.version }}" + BETA_BRANCH="beta/v$VERSION" + + if ! git ls-remote --exit-code origin "$BETA_BRANCH"; then + echo "❌ ERROR: Beta branch '$BETA_BRANCH' does not exist!" + exit 1 + fi + echo "✅ Beta branch '$BETA_BRANCH' exists." + + - name: Check if stable branch already exists + id: check_stable_branch + run: | + VERSION="${{ github.event.inputs.version }}" + STABLE_BRANCH="stable/v$VERSION" + + if git ls-remote --exit-code origin "$STABLE_BRANCH"; then + echo "❌ ERROR: Stable branch '$STABLE_BRANCH' already exists!" + exit 1 + fi + echo "✅ Stable branch '$STABLE_BRANCH' does not exist." + + - name: Create and push new stable branch + run: | + VERSION="${{ github.event.inputs.version }}" + BETA_BRANCH="beta/v$VERSION" + STABLE_BRANCH="stable/v$VERSION" + + # Fetch latest changes + git fetch origin "$BETA_BRANCH" + + # Create new stable branch from beta branch + git checkout -b "$STABLE_BRANCH" origin/"$BETA_BRANCH" + + # Push new stable branch to remote + git push origin "$STABLE_BRANCH" + + echo "✅ Successfully created stable branch '$STABLE_BRANCH' from '$BETA_BRANCH'." + + - name: Merge beta into stable + run: | + VERSION="${{ github.event.inputs.version }}" + BETA_BRANCH="beta/v$VERSION" + STABLE_BRANCH="stable/v$VERSION" + + # Checkout stable branch + git checkout "$STABLE_BRANCH" + + # Merge beta into stable + git merge --no-ff "origin/$BETA_BRANCH" -m "Merge $BETA_BRANCH into $STABLE_BRANCH" + + # Push merge changes + git push origin "$STABLE_BRANCH" + + echo "✅ Successfully merged '$BETA_BRANCH' into '$STABLE_BRANCH'." + + - name: Delete beta branch after successful merge + run: | + VERSION="${{ github.event.inputs.version }}" + BETA_BRANCH="beta/v$VERSION" + + # Delete beta branch locally and remotely + git branch -d "$BETA_BRANCH" + git push origin --delete "$BETA_BRANCH" + + echo "✅ Successfully deleted '$BETA_BRANCH'." + + - name: Create Pull Request to Main + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.PAT }} + commit-message: "Promote stable/v${{ github.event.inputs.version }} to main" + title: "Promote stable/v${{ github.event.inputs.version }} to main" + body: "This PR promotes stable/v${{ github.event.inputs.version }} to the main branch." + base: main + branch: stable/v${{ github.event.inputs.version }} + delete-branch: false diff --git a/.github/workflows/promote-dev-to-beta.yaml b/.github/workflows/promote-dev-to-beta.yaml new file mode 100644 index 00000000..988af0d7 --- /dev/null +++ b/.github/workflows/promote-dev-to-beta.yaml @@ -0,0 +1,99 @@ +name: Promote Dev to Beta + +on: + workflow_dispatch: + inputs: + version: + description: "Version to promote (format: 0.0.0)" + required: true + type: string + +jobs: + promote-dev-to-beta: + name: Promote Dev to Beta + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v4 + with: + token: ${{ secrets.PAT }} # Uses the Personal Access Token + + - name: Validate version format + id: validate_version + run: | + VERSION="${{ github.event.inputs.version }}" + if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "❌ ERROR: Version must be in 'v0.0.0' format." + exit 1 + fi + echo "✅ Version format validated: $VERSION" + + - name: Check if dev branch exists + id: check_dev_branch + run: | + VERSION="${{ github.event.inputs.version }}" + DEV_BRANCH="dev/v$VERSION" + + if ! git ls-remote --exit-code origin "$DEV_BRANCH"; then + echo "❌ ERROR: Dev branch '$DEV_BRANCH' does not exist!" + exit 1 + fi + echo "✅ Dev branch '$DEV_BRANCH' exists." + + - name: Check if beta branch already exists + id: check_beta_branch + run: | + VERSION="${{ github.event.inputs.version }}" + BETA_BRANCH="beta/v$VERSION" + + if git ls-remote --exit-code origin "$BETA_BRANCH"; then + echo "❌ ERROR: Beta branch '$BETA_BRANCH' already exists!" + exit 1 + fi + echo "✅ Beta branch '$BETA_BRANCH' does not exist." + + - name: Create and push new beta branch + run: | + VERSION="${{ github.event.inputs.version }}" + DEV_BRANCH="dev/v$VERSION" + BETA_BRANCH="beta/v$VERSION" + + # Fetch latest changes + git fetch origin "$DEV_BRANCH" + + # Create new beta branch from dev branch + git checkout -b "$BETA_BRANCH" origin/"$DEV_BRANCH" + + # Push new beta branch to remote + git push origin "$BETA_BRANCH" + + echo "✅ Successfully created beta branch '$BETA_BRANCH' from '$DEV_BRANCH'." + + - name: Merge dev into beta + run: | + VERSION="${{ github.event.inputs.version }}" + DEV_BRANCH="dev/v$VERSION" + BETA_BRANCH="beta/v$VERSION" + + # Checkout beta branch + git checkout "$BETA_BRANCH" + + # Merge dev into beta + git merge --no-ff "origin/$DEV_BRANCH" -m "Merge $DEV_BRANCH into $BETA_BRANCH" + + # Push merge changes + git push origin "$BETA_BRANCH" + + echo "✅ Successfully merged '$DEV_BRANCH' into '$BETA_BRANCH'." + + - name: Delete dev branch after successful merge + run: | + VERSION="${{ github.event.inputs.version }}" + DEV_BRANCH="dev/v$VERSION" + + # Delete dev branch locally and remotely + git branch -d "$DEV_BRANCH" + git push origin --delete "$DEV_BRANCH" + + echo "✅ Successfully deleted '$DEV_BRANCH'." diff --git a/.github/workflows/release_beta.yaml b/.github/workflows/release_beta.yaml index ebd3fe4f..eb99dc8b 100644 --- a/.github/workflows/release_beta.yaml +++ b/.github/workflows/release_beta.yaml @@ -9,8 +9,8 @@ permissions: contents: write jobs: - test_frontend: - name: Test Playwright + test_playwright: + name: Test Playwright - regular runs-on: ubuntu-latest steps: - name: Checkout @@ -31,10 +31,10 @@ jobs: uses: docker/build-push-action@v6 with: context: . - file: ./_docker/Dockerfile.playwright + file: ./_docker/Dockerfile.playwright-regular push: false create_release_tag: - needs: [ test_frontend ] + needs: [ test_playwright ] name: Create Release runs-on: ubuntu-latest steps: @@ -63,45 +63,4 @@ jobs: make_latest: true # change this to false when stable gets released draft: false generate_release_notes: true - name: ${{ steps.extract_branch.outputs.tag_name }} - - push_release_to_registry: - needs: [ test_frontend ] - name: Push release - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3.0.0 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3.0.0 - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v5 - with: - images: gtstef/filebrowser - - name: Strip v from version number - id: modify-json - run: | - JSON="${{ steps.meta.outputs.tags }}" - # Use jq to remove 'v' from the version field - JSON=$(echo "$JSON" | sed 's/filebrowser:beta\/v/filebrowser:beta_v/') - echo "cleaned_tag=$JSON" >> $GITHUB_OUTPUT - - name: Build and push - uses: docker/build-push-action@v6 - with: - context: . - build-args: | - VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} - REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }} - platforms: linux/amd64,linux/arm64,linux/arm/v7 - file: ./_docker/Dockerfile - push: true - tags: ${{ steps.modify-json.outputs.cleaned_tag }} - labels: ${{ steps.meta.outputs.labels }} + name: ${{ steps.extract_branch.outputs.tag_name }} \ No newline at end of file diff --git a/.github/workflows/release_dev.yaml b/.github/workflows/release_dev.yaml index 1b3337b3..b889b41b 100644 --- a/.github/workflows/release_dev.yaml +++ b/.github/workflows/release_dev.yaml @@ -29,12 +29,14 @@ jobs: uses: docker/metadata-action@v5 with: images: gtstef/filebrowser - - name: Strip v from version number + - name: modify version names id: modify-json run: | JSON="${{ steps.meta.outputs.tags }}" # Use jq to remove 'v' from the version field - JSON=$(echo "$JSON" | sed 's/filebrowser:dev\/v/filebrowser:dev_v/') + JSON=$(echo "$JSON" | sed 's/filebrowser:dev-v/filebrowser:/') + JSON=$(echo "$JSON" | sed -E 's/(filebrowser:[0-9]+\.[0-9]+\.[0-9]+)/\1-dev/g') + JSON="$JSON,gtstef/filebrowser:dev" echo "cleaned_tag=$JSON" >> $GITHUB_OUTPUT - name: Build and push uses: docker/build-push-action@v6 diff --git a/.github/workflows/release_stable.yaml b/.github/workflows/release_stable.yaml index 423d1c66..fe6346d7 100644 --- a/.github/workflows/release_stable.yaml +++ b/.github/workflows/release_stable.yaml @@ -9,7 +9,7 @@ permissions: contents: write jobs: - test_frontend: + test_playwright: name: Test Playwright runs-on: ubuntu-latest steps: @@ -31,10 +31,10 @@ jobs: uses: docker/build-push-action@v6 with: context: . - file: ./_docker/Dockerfile.playwright + file: ./_docker/Dockerfile.playwright-regular push: false create_release_tag: - needs: [ test_frontend ] + needs: [ test_playwright ] name: Create Release runs-on: ubuntu-latest steps: @@ -63,44 +63,3 @@ jobs: draft: false generate_release_notes: true name: ${{ steps.extract_branch.outputs.tag_name }} - - push_release_to_registry: - needs: [ test_frontend ] - name: Push release - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3.0.0 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3.0.0 - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v5 - with: - images: gtstef/filebrowser - - name: Strip v from version number - id: modify-json - run: | - JSON="${{ steps.meta.outputs.tags }}" - # Use jq to remove 'v' from the version field - JSON=$(echo "$JSON" | sed 's/filebrowser:stable\/v/filebrowser:/') - echo "cleaned_tag=$JSON" >> $GITHUB_OUTPUT - - name: Build and push - uses: docker/build-push-action@v6 - with: - context: . - build-args: | - VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} - REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }} - platforms: linux/amd64,linux/arm64,linux/arm/v7 - file: ./_docker/Dockerfile - push: true - tags: ${{ steps.modify-json.outputs.cleaned_tag }} - labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/tag.yaml b/.github/workflows/tag.yaml index b0aab81c..46d1d392 100644 --- a/.github/workflows/tag.yaml +++ b/.github/workflows/tag.yaml @@ -29,3 +29,50 @@ jobs: workdir: backend env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + push_release_to_registry: + name: Push release + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3.0.0 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.0.0 + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: gtstef/filebrowser + - name: Modify tags (strip 'v' and add 'beta' if needed) + id: modify-json + run: | + JSON="${{ steps.meta.outputs.tags }}" + # Remove 'v' from version tags + JSON=$(echo "$JSON" | sed 's/filebrowser:v/filebrowser:/') + # If the tag includes "beta", append "filebrowser:beta" + if echo "$JSON" | grep -q "beta"; then + JSON="$JSON,gtstef/filebrowser:beta" + fi + if echo "$JSON" | grep -q "stable"; then + JSON="$JSON,gtstef/filebrowser:stable" + fi + echo "cleaned_tag=$JSON" >> $GITHUB_OUTPUT + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + build-args: | + VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} + REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }} + platforms: linux/amd64,linux/arm64,linux/arm/v7 + file: ./_docker/Dockerfile + push: true + tags: ${{ steps.modify-json.outputs.cleaned_tag }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/_docker/Dockerfile.playwright-noauth b/_docker/Dockerfile.playwright-noauth new file mode 100644 index 00000000..12922746 --- /dev/null +++ b/_docker/Dockerfile.playwright-noauth @@ -0,0 +1,8 @@ +FROM gtstef/playwright-base +WORKDIR /app +COPY [ "./_docker/src/noauth/", "./" ] +WORKDIR /app/frontend +COPY [ "./frontend/", "./" ] +WORKDIR /app/backend/ +COPY [ "./backend/filebrowser", "./"] +RUN ./filebrowser & sleep 2 && cd ../frontend && npx playwright test diff --git a/_docker/Dockerfile.playwright-proxy b/_docker/Dockerfile.playwright-proxy new file mode 100644 index 00000000..8494a39c --- /dev/null +++ b/_docker/Dockerfile.playwright-proxy @@ -0,0 +1,10 @@ +FROM gtstef/playwright-base +WORKDIR /app +COPY [ "./_docker/src/proxy/", "./" ] +WORKDIR /app/frontend +COPY [ "./frontend/", "./" ] +WORKDIR /app/backend/ +COPY [ "./backend/filebrowser", "./"] +RUN apt update && apt install nginx -y +RUN mv default.conf /etc/nginx/conf.d/default.conf +RUN nginx & ./filebrowser & sleep 2 && cd ../frontend && npx playwright test diff --git a/_docker/Dockerfile.playwright b/_docker/Dockerfile.playwright-regular similarity index 53% rename from _docker/Dockerfile.playwright rename to _docker/Dockerfile.playwright-regular index 68fb5d01..f0c5d6df 100644 --- a/_docker/Dockerfile.playwright +++ b/_docker/Dockerfile.playwright-regular @@ -1,6 +1,8 @@ FROM gtstef/playwright-base +WORKDIR /app +COPY [ "./_docker/src/regular/", "./" ] WORKDIR /app/frontend COPY [ "./frontend/", "./" ] WORKDIR /app/backend/ COPY [ "./backend/filebrowser*", "./"] -RUN ./filebrowser -c filebrowser-playwright.yaml & sleep 2 && cd ../frontend && npx playwright test +RUN ./filebrowser & sleep 2 && cd ../frontend && npx playwright test diff --git a/_docker/docker-compose.yaml b/_docker/docker-compose.yaml index 4bc9afc0..4a845288 100644 --- a/_docker/docker-compose.yaml +++ b/_docker/docker-compose.yaml @@ -3,13 +3,13 @@ services: image: nginx container_name: nginx-proxy-auth ports: - - "8080:80" + - "80:80" volumes: - - ./src/default.conf:/etc/nginx/conf.d/default.conf + - ./src/proxy/backend/default.conf:/etc/nginx/conf.d/default.conf filebrowser: volumes: - '../frontend:/home/frontend' - - "./src/config.yaml:/home/filebrowser/config.yaml" + - "./src/proxy/backend/config.yaml:/home/filebrowser/config.yaml" build: context: ../ dockerfile: ./_docker/Dockerfile diff --git a/_docker/src/config.yaml b/_docker/src/config.yaml deleted file mode 100644 index 8ffa1fdc..00000000 --- a/_docker/src/config.yaml +++ /dev/null @@ -1,8 +0,0 @@ -server: - port: 80 - baseURL: "/" - root: "../frontend/tests/playwright-files" -auth: - method: proxy - header: X-Username - signup: false \ No newline at end of file diff --git a/_docker/src/noauth/backend/config.yaml b/_docker/src/noauth/backend/config.yaml new file mode 100644 index 00000000..dbc8b963 --- /dev/null +++ b/_docker/src/noauth/backend/config.yaml @@ -0,0 +1,15 @@ +server: + port: 80 + baseURL: "/" + root: "../frontend/tests/playwright-files" +auth: + signup: false + methods: + noauth: true +frontend: + name: "Graham's Filebrowser" + disableDefaultLinks: true + externalLinks: + - text: "A playwright test" + url: "https://playwright.dev/" + title: "Playwright" diff --git a/_docker/src/noauth/frontend/playwright.config.ts b/_docker/src/noauth/frontend/playwright.config.ts new file mode 100644 index 00000000..bca2dd72 --- /dev/null +++ b/_docker/src/noauth/frontend/playwright.config.ts @@ -0,0 +1,47 @@ +import { defineConfig, devices } from "@playwright/test"; + +/** + * Read environment variables from file. + * https://github.com/motdotla/dotenv + */ +// require('dotenv').config(); + +/** + * See https://playwright.dev/docs/test-configuration. + */ +export default defineConfig({ + //globalSetup: "./global-setup", + timeout: 6000, + testDir: "./tests-proxy", + /* Run tests in files in parallel */ + fullyParallel: false, + /* Fail the build on CI if you accidentally left test.only in the source code. */ + forbidOnly: false, + /* Retry on CI only */ + retries: 2, + /* Opt out of parallel tests on CI. */ + workers: 1, // required for now! todo parallel some tests + /* Reporter to use. See https://playwright.dev/docs/test-reporters */ + reporter: "line", + /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ + use: { + actionTimeout: 5000, + //storageState: "loginAuth.json", + /* Base URL to use in actions like `await page.goto('/')`. */ + baseURL: "http://127.0.0.1", + + /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ + trace: "on-first-retry", + + /* Set default locale to English (US) */ + locale: "en-US", + }, + + /* Configure projects for major browsers */ + projects: [ + { + name: "firefox", + use: { ...devices["Desktop Firefox"] }, + }, + ], +}); diff --git a/_docker/src/proxy/backend/config.yaml b/_docker/src/proxy/backend/config.yaml new file mode 100644 index 00000000..bc5a099b --- /dev/null +++ b/_docker/src/proxy/backend/config.yaml @@ -0,0 +1,35 @@ +server: + port: 8080 + baseURL: "/" + root: "../frontend/tests/playwright-files" +frontend: + name: "Graham's Filebrowser" + disableDefaultLinks: true + externalLinks: + - text: "A playwright test" + url: "https://playwright.dev/" + title: "Playwright" +auth: + signup: false + methods: + password: + enabled: false + minLength: 0 + proxy: + enabled: true + header: "X-Username" + createUser: true + +userDefaults: + darkMode: true + disableSettings: false + scope: "." + singleClick: false + permissions: + admin: false + create: false + rename: false + modify: false + delete: false + share: false + download: false diff --git a/_docker/src/default.conf b/_docker/src/proxy/backend/default.conf similarity index 88% rename from _docker/src/default.conf rename to _docker/src/proxy/backend/default.conf index e301ce74..0518390a 100644 --- a/_docker/src/default.conf +++ b/_docker/src/proxy/backend/default.conf @@ -3,7 +3,7 @@ server { server_name localhost 127.0.0.1; location / { - proxy_pass http://filebrowser; + proxy_pass http://localhost:8080; proxy_set_header X-Username "proxy-user"; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; diff --git a/_docker/src/proxy/frontend/playwright.config.ts b/_docker/src/proxy/frontend/playwright.config.ts new file mode 100644 index 00000000..bca2dd72 --- /dev/null +++ b/_docker/src/proxy/frontend/playwright.config.ts @@ -0,0 +1,47 @@ +import { defineConfig, devices } from "@playwright/test"; + +/** + * Read environment variables from file. + * https://github.com/motdotla/dotenv + */ +// require('dotenv').config(); + +/** + * See https://playwright.dev/docs/test-configuration. + */ +export default defineConfig({ + //globalSetup: "./global-setup", + timeout: 6000, + testDir: "./tests-proxy", + /* Run tests in files in parallel */ + fullyParallel: false, + /* Fail the build on CI if you accidentally left test.only in the source code. */ + forbidOnly: false, + /* Retry on CI only */ + retries: 2, + /* Opt out of parallel tests on CI. */ + workers: 1, // required for now! todo parallel some tests + /* Reporter to use. See https://playwright.dev/docs/test-reporters */ + reporter: "line", + /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ + use: { + actionTimeout: 5000, + //storageState: "loginAuth.json", + /* Base URL to use in actions like `await page.goto('/')`. */ + baseURL: "http://127.0.0.1", + + /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ + trace: "on-first-retry", + + /* Set default locale to English (US) */ + locale: "en-US", + }, + + /* Configure projects for major browsers */ + projects: [ + { + name: "firefox", + use: { ...devices["Desktop Firefox"] }, + }, + ], +}); diff --git a/backend/filebrowser-playwright.yaml b/_docker/src/regular/backend/config.yaml similarity index 92% rename from backend/filebrowser-playwright.yaml rename to _docker/src/regular/backend/config.yaml index 0ba42910..5a61e52e 100644 --- a/backend/filebrowser-playwright.yaml +++ b/_docker/src/regular/backend/config.yaml @@ -2,9 +2,6 @@ server: port: 80 baseURL: "/" root: "../frontend/tests/playwright-files" -auth: - method: password - signup: false frontend: name: "Graham's Filebrowser" disableDefaultLinks: true diff --git a/frontend/playwright.config.ts b/_docker/src/regular/frontend/playwright.config.ts similarity index 100% rename from frontend/playwright.config.ts rename to _docker/src/regular/frontend/playwright.config.ts diff --git a/frontend/tests-proxy/preview.spec.ts b/frontend/tests-proxy/preview.spec.ts new file mode 100644 index 00000000..ae283a0d --- /dev/null +++ b/frontend/tests-proxy/preview.spec.ts @@ -0,0 +1,55 @@ +import { test, expect } from "@playwright/test"; + +test("blob file preview", async ({ page, context }) => { + await page.goto("/files/"); + await expect(page).toHaveTitle("Graham's Filebrowser - Files - playwright-files"); + await page.locator('a[aria-label="file.tar.gz"]').waitFor({ state: 'visible' }); + await page.locator('a[aria-label="file.tar.gz"]').dblclick(); + await expect(page).toHaveTitle("Graham's Filebrowser - Files - file.tar.gz"); + await page.locator('button[title="Close"]').click(); + await expect(page).toHaveTitle("Graham's Filebrowser - Files - playwright-files"); +}); + +test("text file editor", async ({ page, context }) => { + await page.goto("/files/"); + await expect(page).toHaveTitle("Graham's Filebrowser - Files - playwright-files"); + await page.locator('a[aria-label="copyme.txt"]').waitFor({ state: 'visible' }); + await page.locator('a[aria-label="copyme.txt"]').dblclick(); + await expect(page).toHaveTitle("Graham's Filebrowser - Files - copyme.txt"); + const firstLineText = await page.locator('.ace_text-layer .ace_line').first().textContent(); + expect(firstLineText).toBe('test file for playwright'); + await page.locator('button[title="Close"]').click(); + await expect(page).toHaveTitle("Graham's Filebrowser - Files - playwright-files"); +}); + +test("navigate folders", async ({ page, context }) => { + await page.goto("/files/"); + await expect(page).toHaveTitle("Graham's Filebrowser - Files - playwright-files"); + await page.locator('a[aria-label="myfolder"]').waitFor({ state: 'visible' }); + await page.locator('a[aria-label="myfolder"]').dblclick(); + await expect(page).toHaveTitle("Graham's Filebrowser - Files - myfolder"); + await page.locator('a[aria-label="testdata"]').waitFor({ state: 'visible' }); + await page.locator('a[aria-label="testdata"]').dblclick(); + await expect(page).toHaveTitle("Graham's Filebrowser - Files - testdata"); + await page.locator('a[aria-label="gray-sample.jpg"]').waitFor({ state: 'visible' }); + await page.locator('a[aria-label="gray-sample.jpg"]').dblclick(); + await expect(page).toHaveTitle("Graham's Filebrowser - Files - gray-sample.jpg"); +}); + +test("navigating images", async ({ page, context }) => { + await page.goto("/files/myfolder/testdata/20130612_142406.jpg"); + await expect(page).toHaveTitle("Graham's Filebrowser - Files - 20130612_142406.jpg"); + await page.locator('button[aria-label="Previous"]').waitFor({ state: 'hidden' }); + await page.mouse.move(100, 100); + await page.locator('button[aria-label="Next"]').waitFor({ state: 'visible' }); + await page.locator('button[aria-label="Next"]').click(); + // went to next image + await expect(page).toHaveTitle("Graham's Filebrowser - Files - gray-sample.jpg"); + await page.locator('button[aria-label="Previous"]').waitFor({ state: 'hidden' }); + await page.locator('button[aria-label="Next"]').waitFor({ state: 'hidden' }); + await page.mouse.move(100, 100); + await page.locator('button[aria-label="Next"]').waitFor({ state: 'visible' }); + //await page.locator('button[aria-label="Next"]').click(); + // went to next image + //await expect(page).toHaveTitle("Graham's Filebrowser - Files - IMG_2578.JPG"); +}); \ No newline at end of file diff --git a/makefile b/makefile index 798addaf..ee09460c 100644 --- a/makefile +++ b/makefile @@ -53,7 +53,11 @@ test-frontend: test-playwright: run-frontend cd backend && GOOS=linux go build -o filebrowser . && cd .. && \ - docker build -t filebrowser-playwright-tests -f _docker/Dockerfile.playwright . + docker build -t filebrowser-playwright-tests -f _docker/Dockerfile.playwright-regular . && \ + docker run --rm --name filebrowser-playwright-tests filebrowser-playwright-tests && \ + docker build -t filebrowser-playwright-tests -f _docker/Dockerfile.playwright-noauth . && \ + docker run --rm --name filebrowser-playwright-tests filebrowser-playwright-tests && \ + docker build -t filebrowser-playwright-tests -f _docker/Dockerfile.playwright-proxy . && \ docker run --rm --name filebrowser-playwright-tests filebrowser-playwright-tests # Run on a windows machine!