|
| 1 | +name: Process Docs Changes |
| 2 | +on: |
| 3 | + # pull_request: |
| 4 | + # branches: |
| 5 | + # - master |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + branch_name: |
| 9 | + description: Which `metabase/metabase` branch triggered this workflow |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + |
| 13 | +jobs: |
| 14 | + build-and-commit: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Display received payload |
| 20 | + run: | |
| 21 | + echo "Got branch_name: ${{ github.event.inputs.branch_name }}" |
| 22 | +
|
| 23 | + - name: Install dependencies |
| 24 | + run: yarn install --frozen-lockfile --prefer-offline |
| 25 | + |
| 26 | + - name: Set up Ruby # uses version from .ruby-version |
| 27 | + uses: ruby/setup-ruby@d5fb7a202fc07872cb44f00ba8e6197b70cb0c55 # v1.179.0 |
| 28 | + with: |
| 29 | + bundler-cache: true |
| 30 | + |
| 31 | + - name: Install dependencies |
| 32 | + run: bundle install |
| 33 | + |
| 34 | + - name: Update docs |
| 35 | + run: | |
| 36 | + ./script/docs-update |
| 37 | + ./script/docs master --set-version master |
| 38 | +
|
| 39 | + - name: "Lint the markdown" |
| 40 | + run: | |
| 41 | + yarn lint-markdown |
| 42 | +
|
| 43 | + - name: "Lint the styles" |
| 44 | + run: | |
| 45 | + yarn lint-styles |
| 46 | +
|
| 47 | + - name: "Lint the scripts" |
| 48 | + run: | |
| 49 | + yarn lint-scripts |
| 50 | +
|
| 51 | + - name: "Validate the links" |
| 52 | + run: | |
| 53 | + yarn lint-links |
| 54 | +
|
| 55 | +
|
| 56 | + - name: Build the Jekyll Site |
| 57 | + env: |
| 58 | + JEKYLL_ENV: staging |
| 59 | + NODE_ENV: production |
| 60 | + run: | |
| 61 | + # Clear the existing site: |
| 62 | + rm -rf _site |
| 63 | + # Run the jekyll server: |
| 64 | + JEKYLL_ENV=development bundle exec jekyll build --baseurl '' --config _config.docs.yml --trace |
| 65 | +
|
| 66 | + - name: Setup Babashka |
| 67 | + uses: turtlequeue/setup-babashka@v1.7.0 |
| 68 | + with: |
| 69 | + babashka-version: 1.12.197 |
| 70 | + - name: Check bb runs |
| 71 | + run: bb --version |
| 72 | + |
| 73 | + - name: "Check all of the links" |
| 74 | + run: | |
| 75 | + script/links || true |
| 76 | + echo 'checking reported links...' |
| 77 | + echo "htmlproofer spit out a report of length: $(cat htmlproofer.out | wc -l)" |
| 78 | + bb script/analyze_links.clj --htmlproofer-output htmlproofer.out |
| 79 | +
|
| 80 | + - name: Create the pull request |
| 81 | + env: |
| 82 | + GH_TOKEN: ${{ secrets.METABASE_AUTOMATION_USER_TOKEN }} |
| 83 | + run: | |
| 84 | + if git diff --quiet ; then |
| 85 | + echo "No changes to commit." |
| 86 | + else |
| 87 | + git config user.email "metabase-bot@metabase.com" |
| 88 | + git config user.name "Metabase Docs bot" |
| 89 | + update_branch="docs-update" |
| 90 | +
|
| 91 | + # Check out or create the update branch |
| 92 | + if git ls-remote --exit-code --heads origin "$update_branch" > /dev/null; then |
| 93 | + git fetch origin "$update_branch" |
| 94 | + git switch "$update_branch" |
| 95 | + else |
| 96 | + git switch --create "$update_branch" |
| 97 | + fi |
| 98 | +
|
| 99 | + git add _site |
| 100 | + git commit --author="Metabase Docs bot <metabase-bot@metabase.com>" --message="Update master and latest docs" |
| 101 | + git push --force origin "$update_branch" |
| 102 | +
|
| 103 | + # Check if a PR already exists for this branch |
| 104 | + existing_pr=$(gh pr list --head "$update_branch" --json number --jq '.[0].number') |
| 105 | +
|
| 106 | + if [ -z "$existing_pr" ]; then |
| 107 | + gh pr create \ |
| 108 | + --title "Refresh docs (${{ github.event.inputs.branch_name }})" \ |
| 109 | + --body "" \ |
| 110 | + --head "$update_branch" |
| 111 | + else |
| 112 | + echo "PR already exists: #$existing_pr" |
| 113 | + fi |
| 114 | + fi |
0 commit comments