|
| 1 | +--- |
| 2 | +name: Publish Docs |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_call: |
| 6 | + inputs: |
| 7 | + tag: |
| 8 | + type: string |
| 9 | + description: The tag to use for creating docs branch or merging to docs branch. |
| 10 | + required: true |
| 11 | + |
| 12 | +jobs: |
| 13 | + docs: |
| 14 | + name: publish docs |
| 15 | + runs-on: ubuntu-latest |
| 16 | + env: |
| 17 | + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |
| 18 | + SLACK_CHANNEL: '#oss-releases' |
| 19 | + steps: |
| 20 | + - name: Get github app token |
| 21 | + uses: actions/create-github-app-token@af35edadc00be37caa72ed9f3e6d5f7801bfdf09 # v1.11.7 |
| 22 | + id: gh-app-token |
| 23 | + with: |
| 24 | + app-id: ${{ vars.GH_APP_ID }} |
| 25 | + private-key: ${{ secrets.GH_APP_PRIVATE_KEY }} |
| 26 | + |
| 27 | + - name: Checkout tag |
| 28 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 29 | + with: |
| 30 | + ref: ${{ inputs.tag }} |
| 31 | + token: ${{ steps.gh-app-token.outputs.token }} |
| 32 | + |
| 33 | + - name: Slack notification |
| 34 | + uses: act10ns/slack@44541246747a30eb3102d87f7a4cc5471b0ffb7d # v2.1.0 |
| 35 | + with: |
| 36 | + status: starting |
| 37 | + steps: ${{ toJson(steps) }} |
| 38 | + channel: ${{ env.SLACK_CHANNEL }} |
| 39 | + message: Starting creating docs for ${{ github.repository }} with tag ${{ |
| 40 | + inputs.tag }}...... |
| 41 | + if: always() |
| 42 | + |
| 43 | + - name: Validate Tag |
| 44 | + id: validate_tag |
| 45 | + run: |- |
| 46 | + TAG="${{ inputs.tag }}" |
| 47 | + echo "Validating tag: $TAG" |
| 48 | +
|
| 49 | + # Check if the tag matches the semantic versioning pattern |
| 50 | + if ! echo "$TAG" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' > /dev/null; then |
| 51 | + echo "Error: Tag '$TAG' is not a valid semantic version." |
| 52 | + exit 1 |
| 53 | + fi |
| 54 | +
|
| 55 | + IFS='.' read -r MAJOR MINOR PATCH <<< "${TAG#v}" |
| 56 | +
|
| 57 | + echo "Major: $MAJOR, Minor: $MINOR, Patch: $PATCH" |
| 58 | + RELEASE_BRANCH="release-v${MAJOR}.${MINOR}.0" |
| 59 | + DOCS_BRANCH="docs-v${MAJOR}.${MINOR}.0" |
| 60 | +
|
| 61 | + echo "DOCS_BRANCH=${DOCS_BRANCH}" >> $GITHUB_OUTPUT |
| 62 | + echo "RELEASE_BRANCH=${RELEASE_BRANCH}" >> $GITHUB_OUTPUT |
| 63 | +
|
| 64 | + if [ "$PATCH" -ne 0 ]; then |
| 65 | + # If it's a patch version, create a PR to merge release branch into docs branch |
| 66 | + echo "Creating PR to merge ${RELEASE_BRANCH} into ${DOCS_BRANCH}" |
| 67 | + echo "PR_TITLE=chore: Merge ${RELEASE_BRANCH} into ${DOCS_BRANCH}" |
| 68 | + else |
| 69 | + # If the patch version is zero, create a new docs branch |
| 70 | + echo "Creating new docs branch ${DOCS_BRANCH}" |
| 71 | + fi |
| 72 | + echo "PR_TITLE=${PR_TITLE:-}" >> $GITHUB_OUTPUT |
| 73 | +
|
| 74 | + - name: Create Pull Request for Docs |
| 75 | + if: ${{ steps.validate_tag.outputs.PR_TITLE != '' }} |
| 76 | + uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8 |
| 77 | + with: |
| 78 | + token: ${{ steps.gh-app-token.outputs.token }} |
| 79 | + title: ${{ steps.validate_tag.outputs.PR_TITLE }} |
| 80 | + body: Automatically generated PR to merge release branch into docs branch |
| 81 | + for patch version update. |
| 82 | + base: ${{ steps.validate_tag.outputs.DOCS_BRANCH }} |
| 83 | + sign-commits: true |
| 84 | + branch: ${{ steps.validate_tag.outputs.RELEASE_BRANCH }} |
| 85 | + commit-message: ${{ steps.validate_tag.outputs.PR_TITLE }} |
| 86 | + |
| 87 | + - name: Create Docs Branch |
| 88 | + if: ${{ steps.validate_tag.outputs.PR_TITLE == '' }} |
| 89 | + run: | |
| 90 | + echo "Creating docs branch ${DOCS_BRANCH}" |
| 91 | +
|
| 92 | + git checkout -b "${DOCS_BRANCH}" |
| 93 | + git push origin "${DOCS_BRANCH}" |
| 94 | + env: |
| 95 | + DOCS_BRANCH: ${{ steps.validate_tag.outputs.DOCS_BRANCH }} |
0 commit comments