|
| 1 | +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/deploy-cobra-mkdocs-versioned-poetry.md |
| 2 | +name: Deploy Website |
| 3 | + |
| 4 | +env: |
| 5 | + # See: https://github.com/actions/setup-go/tree/v2#readme |
| 6 | + GO_VERSION: "1.16" |
| 7 | + # See: https://github.com/actions/setup-python/tree/v2#available-versions-of-python |
| 8 | + PYTHON_VERSION: "3.9" |
| 9 | + |
| 10 | +on: |
| 11 | + push: |
| 12 | + branches: |
| 13 | + # Branch to base "dev" website on. Set in siteversion.py also. |
| 14 | + - master |
| 15 | + # Release branches have names like 0.8.x, 0.9.x, ... |
| 16 | + - "[0-9]+.[0-9]+.x" |
| 17 | + paths: |
| 18 | + - "docs/**" |
| 19 | + - ".github/workflows/deploy-cobra-mkdocs-versioned-poetry.ya?ml" |
| 20 | + - "go.mod" |
| 21 | + - "go.sum" |
| 22 | + - "Taskfile.ya?ml" |
| 23 | + - "**.go" |
| 24 | + - "docsgen/**" |
| 25 | + - "rpc/**" |
| 26 | + - "mkdocs.ya?ml" |
| 27 | + - "poetry.lock" |
| 28 | + - "pyproject.toml" |
| 29 | + # Run on branch or tag creation (will be filtered by the publish-determination job). |
| 30 | + create: |
| 31 | + |
| 32 | +jobs: |
| 33 | + publish-determination: |
| 34 | + runs-on: ubuntu-latest |
| 35 | + outputs: |
| 36 | + result: ${{ steps.determination.outputs.result }} |
| 37 | + steps: |
| 38 | + - name: Determine if documentation should be published on this workflow run |
| 39 | + id: determination |
| 40 | + run: | |
| 41 | + RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x" |
| 42 | + if [[ "${{ github.event_name }}" == "push" || ( "${{ github.event_name }}" == "create" && "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX ) ]]; then |
| 43 | + RESULT="true" |
| 44 | + else |
| 45 | + RESULT="false" |
| 46 | + fi |
| 47 | +
|
| 48 | + echo "::set-output name=result::$RESULT" |
| 49 | +
|
| 50 | + publish: |
| 51 | + runs-on: ubuntu-latest |
| 52 | + needs: publish-determination |
| 53 | + if: needs.publish-determination.outputs.result == 'true' |
| 54 | + |
| 55 | + steps: |
| 56 | + - name: Checkout repository |
| 57 | + uses: actions/checkout@v2 |
| 58 | + |
| 59 | + - name: Install Go |
| 60 | + uses: actions/setup-go@v2 |
| 61 | + with: |
| 62 | + go-version: ${{ env.GO_VERSION }} |
| 63 | + |
| 64 | + - name: Install Go dependencies |
| 65 | + run: go install github.com/pseudomuto/protoc-gen-doc/cmd/[email protected] |
| 66 | + |
| 67 | + - name: Install protoc compiler |
| 68 | + uses: arduino/setup-protoc@v1 |
| 69 | + with: |
| 70 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 71 | + |
| 72 | + - name: Install Python |
| 73 | + uses: actions/setup-python@v2 |
| 74 | + with: |
| 75 | + python-version: ${{ env.PYTHON_VERSION }} |
| 76 | + |
| 77 | + - name: Install Poetry |
| 78 | + run: | |
| 79 | + python -m pip install --upgrade pip |
| 80 | + python -m pip install poetry |
| 81 | +
|
| 82 | + - name: Install Task |
| 83 | + uses: arduino/setup-task@v1 |
| 84 | + with: |
| 85 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 86 | + version: 3.x |
| 87 | + |
| 88 | + - name: Create all generated documentation content |
| 89 | + run: task docs:generate |
| 90 | + |
| 91 | + - name: Install Python dependencies |
| 92 | + run: poetry install --no-root |
| 93 | + |
| 94 | + - name: Determine versioning parameters |
| 95 | + id: determine-versioning |
| 96 | + run: echo "::set-output name=data::$(poetry run python docs/siteversion/siteversion.py)" |
| 97 | + |
| 98 | + - name: Publish documentation |
| 99 | + if: fromJson(steps.determine-versioning.outputs.data).version != null |
| 100 | + run: | |
| 101 | + # Publishing implies creating a git commit on the gh-pages branch, we let @ArduinoBot own these commits. |
| 102 | + git config --global user.email "[email protected]" |
| 103 | + git config --global user.name "ArduinoBot" |
| 104 | + git fetch --no-tags --prune --depth=1 origin +refs/heads/gh-pages:refs/remotes/origin/gh-pages |
| 105 | + poetry run mike deploy \ |
| 106 | + --update-aliases \ |
| 107 | + --push \ |
| 108 | + --remote origin \ |
| 109 | + ${{ fromJson(steps.determine-versioning.outputs.data).version }} \ |
| 110 | + ${{ fromJson(steps.determine-versioning.outputs.data).alias }} |
0 commit comments