|
| 1 | +name: Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - v[0-9]+.[0-9]+.[0-9]+ |
| 7 | + |
| 8 | +jobs: |
| 9 | + deploy: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + environment: mkdocs |
| 12 | + |
| 13 | + steps: |
| 14 | + - name: Checkout to the branch of the tag |
| 15 | + run: | |
| 16 | + # checkout from GitHub CI without using actions/checkout |
| 17 | + git clone https://oauth2:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git . |
| 18 | + git fetch origin ${{ github.ref_name }} |
| 19 | +
|
| 20 | + # check if git tag is the last commit of some branch |
| 21 | + TAG=${{ github.ref_name }} |
| 22 | + git branch -a --contains $TAG |
| 23 | + BRANCH=$(git branch -a --contains $TAG | grep -v HEAD | head -n 1 | sed 's/^* //' | sed 's/^ //') |
| 24 | + echo "branch: $BRANCH" |
| 25 | + LAST_COMMIT=$(git rev-parse $BRANCH) |
| 26 | + echo "last commit hash: $LAST_COMMIT" |
| 27 | + TAG_COMMIT=$(git rev-list -n 1 $TAG) |
| 28 | + echo "tag commit hash: $TAG_COMMIT" |
| 29 | +
|
| 30 | + if [[ "$LAST_COMMIT" != "$TAG_COMMIT" ]]; then |
| 31 | + echo "ERROR: Tag $TAG is NOT the last commit of branch $BRANCH. Exiting.." |
| 32 | + exit 1 |
| 33 | + fi |
| 34 | +
|
| 35 | + git checkout "$BRANCH" |
| 36 | +
|
| 37 | + - name: Update CHANGELOG |
| 38 | + id: changelog |
| 39 | + uses: requarks/changelog-action@v1 |
| 40 | + with: |
| 41 | + includeInvalidCommits: true |
| 42 | + excludeTypes: build,docs,style |
| 43 | + token: ${{ github.token }} |
| 44 | + tag: ${{ github.ref_name }} |
| 45 | + |
| 46 | + - name: Commit CHANGELOG.md |
| 47 | + run: | |
| 48 | + git config user.name github-actions |
| 49 | + git config user.email github-actions@github.com |
| 50 | + git tag -d ${{ github.ref_name }} |
| 51 | + git push origin --delete ${{ github.ref_name }} |
| 52 | + git add CHANGELOG.md |
| 53 | + git commit -m "docs: update CHANGELOG.md for ${{ github.ref_name }} [skip ci]" |
| 54 | + git tag -a ${{ github.ref_name }} -m ${{ github.ref_name }} |
| 55 | + git push |
| 56 | + git push --tags |
| 57 | +
|
| 58 | + - name: Create Release |
| 59 | + uses: ncipollo/release-action@v1.12.0 |
| 60 | + with: |
| 61 | + allowUpdates: true |
| 62 | + draft: false |
| 63 | + makeLatest: true |
| 64 | + name: ${{ github.ref_name }} |
| 65 | + body: ${{ steps.changelog.outputs.changes }} |
| 66 | + token: ${{ github.token }} |
| 67 | + |
| 68 | + - name: Set up Python ${{ matrix.python-version }} |
| 69 | + uses: actions/setup-python@v4 |
| 70 | + with: |
| 71 | + python-version: 3.11 |
| 72 | + - name: Install dependencies |
| 73 | + run: | |
| 74 | + python -m pip install --upgrade pip |
| 75 | + pip3 install -r requirements_docs.txt |
| 76 | + - name: Run mkdocs |
| 77 | + run: | |
| 78 | + set +e # Do not exit shell on failure |
| 79 | + export GL_PROJECT=kiyoon/python-project-template-docs |
| 80 | + export HTTPS_REMOTE="https://gitlab-ci-token:${{ secrets.GL_TOKEN }}@gitlab.com/$GL_PROJECT.git" |
| 81 | +
|
| 82 | + git config user.name github-actions |
| 83 | + git config user.email github-actions@github.com |
| 84 | + git remote add gitlab "$HTTPS_REMOTE" |
| 85 | + git branch -D gl-pages |
| 86 | + git pull gitlab gl-pages:gl-pages |
| 87 | +
|
| 88 | + # Delete the latest page because we're going to make it as an alias to the latest version. |
| 89 | + mike delete --deploy-prefix public -r $HTTPS_REMOTE -b gl-pages latest |
| 90 | + out=$(mike deploy --deploy-prefix public -r $HTTPS_REMOTE -p -b gl-pages -u ${{ github.ref_name }} latest 2> stderr.txt) |
| 91 | + exit_code=$? |
| 92 | + err=$(<stderr.txt) |
| 93 | +
|
| 94 | + mike set-default --deploy-prefix public -r $HTTPS_REMOTE -p -b gl-pages latest |
| 95 | +
|
| 96 | + # Display the raw output in the step |
| 97 | + echo "${out}" |
| 98 | + echo "${err}" |
| 99 | +
|
| 100 | + # Display the Markdown output in the job summary |
| 101 | + echo "\`\`\`python" >> $GITHUB_STEP_SUMMARY |
| 102 | + echo "${out}" >> $GITHUB_STEP_SUMMARY |
| 103 | + echo "${err}" >> $GITHUB_STEP_SUMMARY |
| 104 | + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |
| 105 | +
|
| 106 | + exit ${exit_code} |
0 commit comments