|
| 1 | +name: Reusable Publish docs |
| 2 | + |
| 3 | +env: |
| 4 | + BRANCH: main |
| 5 | + ORIGIN: aws-powertools/powertools-lambda-java |
| 6 | + VERSION: "" |
| 7 | + |
| 8 | +on: |
| 9 | + workflow_call: |
| 10 | + inputs: |
| 11 | + version: |
| 12 | + description: "Version to build and publish docs (1.28.0, develop)" |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + alias: |
| 16 | + description: "Alias to associate version (latest, stage)" |
| 17 | + required: true |
| 18 | + type: string |
| 19 | + detached_mode: |
| 20 | + description: "Whether it's running in git detached mode to ensure git is sync'd" |
| 21 | + required: false |
| 22 | + default: false |
| 23 | + type: boolean |
| 24 | + |
| 25 | +permissions: |
| 26 | + contents: write |
| 27 | + id-token: write |
| 28 | + pages: write |
| 29 | + |
| 30 | +jobs: |
| 31 | + publish-docs: |
| 32 | + runs-on: ubuntu-latest |
| 33 | + environment: Docs |
| 34 | + steps: |
| 35 | + - name: Checkout code |
| 36 | + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 |
| 37 | + with: |
| 38 | + # While `fetch-depth` is used to allow the workflow to later commit & push the changes. |
| 39 | + fetch-depth: 0 |
| 40 | + - name: Set up Python |
| 41 | + uses: actions/setup-python@57ded4d7d5e986d7296eab16560982c6dd7c923b # v4.6.0 |
| 42 | + with: |
| 43 | + python-version: "3.8" |
| 44 | + - name: Install doc generation dependencies |
| 45 | + run: | |
| 46 | + pip install --upgrade pip |
| 47 | + pip install -r docs/requirements.txt |
| 48 | + - name: Setup doc deploy |
| 49 | + run: | |
| 50 | + git config --global user.name Docs deploy |
| 51 | + git config --global user.email [email protected] |
| 52 | + - name: Git refresh tip (detached mode) |
| 53 | + # Git Detached mode (release notes) doesn't have origin |
| 54 | + if: ${{ inputs.detached_mode }} |
| 55 | + run: | |
| 56 | + git config pull.rebase true |
| 57 | + git config remote.origin.url >&- || git remote add origin https://github.com/"$ORIGIN" |
| 58 | + git pull origin "$BRANCH" |
| 59 | + - name: Normalize Version Number |
| 60 | + run: echo "VERSION=$(echo ${{ inputs.version }} | sed 's/v//')" >> $GITHUB_ENV |
| 61 | + - name: Build docs website and API reference |
| 62 | + env: |
| 63 | + ALIAS: ${{ inputs.alias }} |
| 64 | + run: | |
| 65 | + rm -rf site |
| 66 | + mkdocs build |
| 67 | + mike deploy --update-aliases --no-redirect ${{ env.VERSION }} ${{ env.ALIAS }} --branch backup-gh-pages |
| 68 | + # Set latest version as a default |
| 69 | + mike set-default latest --branch backup-gh-pages |
| 70 | + - name: Configure AWS credentials |
| 71 | + uses: aws-actions/configure-aws-credentials@e1e17a757e536f70e52b5a12b2e8d1d1c60e04ef # v2.0.0 |
| 72 | + with: |
| 73 | + aws-region: us-east-1 |
| 74 | + role-to-assume: ${{ secrets.AWS_DOCS_ROLE_ARN }} |
| 75 | + - name: Deploy Docs (Version) |
| 76 | + env: |
| 77 | + VERSION: ${{ inputs.version }} |
| 78 | + ALIAS: ${{ inputs.alias }} |
| 79 | + run: | |
| 80 | + aws s3 sync \ |
| 81 | + site/ \ |
| 82 | + s3://${{ secrets.AWS_DOCS_BUCKET }}/lambda-java/${{ env.VERSION }}/ |
| 83 | + - name: Deploy Docs (Alias) |
| 84 | + env: |
| 85 | + VERSION: ${{ inputs.version }} |
| 86 | + ALIAS: ${{ inputs.alias }} |
| 87 | + run: | |
| 88 | + aws s3 sync \ |
| 89 | + site/ \ |
| 90 | + s3://${{ secrets.AWS_DOCS_BUCKET }}/lambda-java/${{ env.ALIAS }}/ |
| 91 | + - name: Deploy Docs (Version JSON) |
| 92 | + env: |
| 93 | + VERSION: ${{ inputs.version }} |
| 94 | + ALIAS: ${{ inputs.alias }} |
| 95 | + |
| 96 | + |
| 97 | + # We originally used "mike" from PyPi to manage versions for us, but since we moved to S3, we can't use it to manage versions any more. |
| 98 | + # Instead, we're using some shell script that manages the versions. |
| 99 | + # |
| 100 | + # Operations: |
| 101 | + # 1. Download the versions.json file from S3 |
| 102 | + # 2. Find any reference to the alias and delete it from the versions file |
| 103 | + # 3. This is voodoo (don't use JQ): |
| 104 | + # - we assign the input as $o and the new version/alias as $n, |
| 105 | + # - we check if the version number exists in the file already (for republishing docs) |
| 106 | + # - if it's an alias (stage/latest/*) or old version, we do nothing and output $o (original input) |
| 107 | + # - if it's a new version number, we add it at position 0 in the array. |
| 108 | + # 4. Once done, we'll upload it back to S3. |
| 109 | + |
| 110 | + run: | |
| 111 | + aws s3 cp \ |
| 112 | + s3://${{ secrets.AWS_DOCS_BUCKET }}/lambda-java/versions.json \ |
| 113 | + versions_old.json |
| 114 | + jq 'del(.[].aliases[] | select(. == "${{ env.ALIAS }}"))' < versions_old.json > versions_proc.json |
| 115 | + jq '. as $o | [{"title": "${{ env.VERSION }}", "version": "${{ env.VERSION }}", "aliases": ["${{env.ALIAS}}"] }] as $n | $n | if .[0].title | test("[a-z]+") or any($o[].title == "${{ env.VERSION }}";.) then $o else $n + $o end' < versions_proc.json > versions.json |
| 116 | + aws s3 cp \ |
| 117 | + versions.json \ |
| 118 | + s3://${{ secrets.AWS_DOCS_BUCKET }}/lambda-java/versions.json |
0 commit comments