|
| 1 | +# SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +name: Documentation Screenshots |
| 5 | + |
| 6 | +on: |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + server-branch: |
| 10 | + description: 'Server branch to screenshot against (e.g. master, stable30)' |
| 11 | + required: false |
| 12 | + default: 'master' |
| 13 | + open-docs-pr: |
| 14 | + description: 'Open a PR against nextcloud/documentation with the screenshots' |
| 15 | + type: boolean |
| 16 | + required: false |
| 17 | + default: true |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: read |
| 21 | + |
| 22 | +env: |
| 23 | + APP_NAME: ${{ github.event.repository.name }} |
| 24 | + BRANCH: ${{ inputs.server-branch || 'master' }} |
| 25 | + |
| 26 | +jobs: |
| 27 | + screenshots: |
| 28 | + runs-on: ubuntu-latest |
| 29 | + name: Capture documentation screenshots |
| 30 | + |
| 31 | + steps: |
| 32 | + - name: Checkout app |
| 33 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 34 | + with: |
| 35 | + persist-credentials: false |
| 36 | + |
| 37 | + - name: Check composer.json |
| 38 | + id: check_composer |
| 39 | + uses: andstor/file-existence-action@558493d6c74bf472d87c84eab196434afc2fa029 # v3.1.0 |
| 40 | + with: |
| 41 | + files: 'composer.json' |
| 42 | + |
| 43 | + - name: Install composer dependencies |
| 44 | + if: steps.check_composer.outputs.files_exists == 'true' |
| 45 | + run: composer install --no-dev |
| 46 | + |
| 47 | + - name: Read package.json node and npm engines version |
| 48 | + uses: skjnldsv/read-package-engines-version-actions@06d6baf7d8f41934ab630e97d9e6c0bc9c9ac5e4 # v3 |
| 49 | + id: versions |
| 50 | + with: |
| 51 | + fallbackNode: '^24' |
| 52 | + fallbackNpm: '^11.3' |
| 53 | + |
| 54 | + - name: Set up node ${{ steps.versions.outputs.nodeVersion }} |
| 55 | + uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 |
| 56 | + with: |
| 57 | + node-version: ${{ steps.versions.outputs.nodeVersion }} |
| 58 | + |
| 59 | + - name: Set up npm ${{ steps.versions.outputs.npmVersion }} |
| 60 | + run: npm i -g 'npm@${{ steps.versions.outputs.npmVersion }}' |
| 61 | + |
| 62 | + - name: Install node dependencies & build app |
| 63 | + run: | |
| 64 | + npm ci |
| 65 | + TESTING=true npm run build --if-present |
| 66 | +
|
| 67 | + - name: Run screenshot specs |
| 68 | + uses: cypress-io/github-action@783cb3f07983868532cabaedaa1e6c00ff4786a8 # v7.1.9 |
| 69 | + with: |
| 70 | + component: false |
| 71 | + spec: cypress/e2e/screenshots.cy.ts |
| 72 | + env: |
| 73 | + CYPRESS_BRANCH: ${{ env.BRANCH }} |
| 74 | + TESTING: true |
| 75 | + |
| 76 | + - name: Upload user screenshots |
| 77 | + uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 |
| 78 | + if: always() |
| 79 | + with: |
| 80 | + name: screenshots-user |
| 81 | + path: cypress/snapshots/actual/screenshots.cy.ts/user/ |
| 82 | + if-no-files-found: warn |
| 83 | + retention-days: 5 |
| 84 | + |
| 85 | + - name: Upload admin screenshots |
| 86 | + uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 |
| 87 | + if: always() |
| 88 | + with: |
| 89 | + name: screenshots-admin |
| 90 | + path: cypress/snapshots/actual/screenshots.cy.ts/admin/ |
| 91 | + if-no-files-found: warn |
| 92 | + retention-days: 5 |
| 93 | + |
| 94 | + # Opens a PR against nextcloud/documentation with updated screenshots. |
| 95 | + # Uses the org-wide COMMAND_BOT_PAT secret. |
| 96 | + # The step is skipped gracefully if the secret is not configured. |
| 97 | + - name: Check if docs PR should be created |
| 98 | + id: docs-pr-check |
| 99 | + env: |
| 100 | + COMMAND_BOT_PAT: ${{ secrets.COMMAND_BOT_PAT }} |
| 101 | + OPEN_DOCS_PR: ${{ inputs.open-docs-pr }} |
| 102 | + run: | |
| 103 | + echo "::group::Debug info" |
| 104 | + echo "inputs.open-docs-pr = '${OPEN_DOCS_PR}'" |
| 105 | + echo "COMMAND_BOT_PAT is set = $([ -n "$COMMAND_BOT_PAT" ] && echo 'yes' || echo 'no')" |
| 106 | + echo "event_name = ${{ github.event_name }}" |
| 107 | + echo "::endgroup::" |
| 108 | +
|
| 109 | + if [ -z "$COMMAND_BOT_PAT" ]; then |
| 110 | + echo "COMMAND_BOT_PAT is not set, skipping docs PR." |
| 111 | + echo "should_run=false" >> "$GITHUB_OUTPUT" |
| 112 | + elif [ "$OPEN_DOCS_PR" = "false" ]; then |
| 113 | + echo "open-docs-pr is false, skipping docs PR." |
| 114 | + echo "should_run=false" >> "$GITHUB_OUTPUT" |
| 115 | + else |
| 116 | + echo "Will attempt to create docs PR." |
| 117 | + echo "should_run=true" >> "$GITHUB_OUTPUT" |
| 118 | + fi |
| 119 | +
|
| 120 | + - name: Open PR against nextcloud/documentation |
| 121 | + if: steps.docs-pr-check.outputs.should_run == 'true' |
| 122 | + env: |
| 123 | + COMMAND_BOT_PAT: ${{ secrets.COMMAND_BOT_PAT }} |
| 124 | + run: | |
| 125 | + set -e |
| 126 | + DOCS_BRANCH="chore/activity-screenshots-$(date +%Y%m%d-%H%M%S)" |
| 127 | + SCREENSHOT_DIR="cypress/snapshots/actual/screenshots.cy.ts" |
| 128 | +
|
| 129 | + git clone --depth 1 "https://x-access-token:${COMMAND_BOT_PAT}@github.com/nextcloud/documentation.git" /tmp/documentation |
| 130 | + cd /tmp/documentation |
| 131 | +
|
| 132 | + git config user.name "nextcloud-command" |
| 133 | + git config user.email "nextcloud-command@users.noreply.github.com" |
| 134 | + git checkout -b "$DOCS_BRANCH" |
| 135 | +
|
| 136 | + # Copy user screenshots |
| 137 | + if [ -d "$GITHUB_WORKSPACE/$SCREENSHOT_DIR/user" ]; then |
| 138 | + cp "$GITHUB_WORKSPACE/$SCREENSHOT_DIR/user/"*.png user_manual/images/ |
| 139 | + echo "Copied user screenshots" |
| 140 | + else |
| 141 | + echo "WARNING: No user screenshot directory at $SCREENSHOT_DIR/user" |
| 142 | + fi |
| 143 | +
|
| 144 | + # Copy admin screenshots |
| 145 | + if [ -d "$GITHUB_WORKSPACE/$SCREENSHOT_DIR/admin" ]; then |
| 146 | + cp "$GITHUB_WORKSPACE/$SCREENSHOT_DIR/admin/"*.png admin_manual/images/ |
| 147 | + echo "Copied admin screenshots" |
| 148 | + else |
| 149 | + echo "WARNING: No admin screenshot directory at $SCREENSHOT_DIR/admin" |
| 150 | + fi |
| 151 | +
|
| 152 | + # Check if there are changes to commit |
| 153 | + if git diff --quiet && [ -z "$(git ls-files --others --exclude-standard)" ]; then |
| 154 | + echo "No screenshot changes detected, skipping PR." |
| 155 | + exit 0 |
| 156 | + fi |
| 157 | +
|
| 158 | + # Build PR title with branch prefix for stable branches |
| 159 | + if [ "$BRANCH" != "master" ]; then |
| 160 | + PR_TITLE="[$BRANCH] chore: update activity app screenshots" |
| 161 | + else |
| 162 | + PR_TITLE="chore: update activity app screenshots" |
| 163 | + fi |
| 164 | +
|
| 165 | + git add user_manual/images/activity-*.png admin_manual/images/activity-*.png |
| 166 | + git diff --cached --stat |
| 167 | + git commit -s -m "$PR_TITLE" |
| 168 | + git push origin "$DOCS_BRANCH" |
| 169 | + echo "Pushed branch $DOCS_BRANCH" |
| 170 | +
|
| 171 | + GH_TOKEN="${COMMAND_BOT_PAT}" gh pr create \ |
| 172 | + --repo nextcloud/documentation \ |
| 173 | + --base master \ |
| 174 | + --head "$DOCS_BRANCH" \ |
| 175 | + --title "$PR_TITLE" \ |
| 176 | + --body "$(cat <<EOF |
| 177 | + ## Summary |
| 178 | + - Automated screenshot update from the [Activity app](https://github.com/nextcloud/activity) CI |
| 179 | + - Screenshots captured against server branch \`${BRANCH}\` |
| 180 | +
|
| 181 | + ### User manual images |
| 182 | + $(cd "$GITHUB_WORKSPACE" && ls $SCREENSHOT_DIR/user/*.png 2>/dev/null | xargs -I{} basename {} | sed 's/^/- /' || echo "- (none)") |
| 183 | +
|
| 184 | + ### Admin manual images |
| 185 | + $(cd "$GITHUB_WORKSPACE" && ls $SCREENSHOT_DIR/admin/*.png 2>/dev/null | xargs -I{} basename {} | sed 's/^/- /' || echo "- (none)") |
| 186 | +
|
| 187 | + --- |
| 188 | + Generated automatically by the Activity app [screenshot workflow](https://github.com/nextcloud/activity/actions/workflows/screenshots.yml). |
| 189 | + EOF |
| 190 | + )" |
| 191 | +
|
| 192 | + echo "PR created successfully" |
| 193 | +
|
| 194 | + - name: Extract NC logs |
| 195 | + if: failure() |
| 196 | + run: docker logs nextcloud-cypress-tests-${{ env.APP_NAME }} > nextcloud.log 2>&1 |
| 197 | + |
| 198 | + - name: Upload NC logs |
| 199 | + uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 |
| 200 | + if: failure() |
| 201 | + with: |
| 202 | + name: nc-logs |
| 203 | + path: nextcloud.log |
0 commit comments