diff --git a/.github/workflows/doxygen.yml b/.github/workflows/doxygen.yml index d06766dd..b75c33fe 100644 --- a/.github/workflows/doxygen.yml +++ b/.github/workflows/doxygen.yml @@ -12,10 +12,26 @@ jobs: runs-on: ubuntu-latest if: github.event.pull_request.merged == true steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: persist-credentials: false fetch-depth: 0 + - name: Switch to gh-pages branch + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + shell: bash + run: | + # Check if the gh-pages branch exists. If not, create it. + branch_exist=$(git ls-remote --heads origin gh-pages) + if [ -z ${branch_exist} ]; then + git checkout --orphan gh-pages + git reset --hard + git commit --allow-empty -m "Created gh-pages branch" + git push origin gh-pages + fi + # Switch to gh-pages branch + git fetch + git checkout gh-pages - name: Create local changes run: | sudo apt-get install doxygen @@ -24,14 +40,16 @@ jobs: cp -r ./html/* ./ rm -rf ./html git add . - - name: Commit files + - name: Commit and push files + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" - git config --local user.name "github-actions[bot]" - git commit -m "Auto-generate Doxygen documentation via Github Actions" -a - - name: Push changes - uses: ad-m/github-push-action@master - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - branch: gh-pages - force: true + git config --global user.name ${{ github.actor }} + git config --global user.email ${{ github.actor }}@users.noreply.github.com + git add . + # Only commit if doxygen is changed. + changed=$(git diff-index HEAD) + if [ -n "$changed" ]; then + git commit -m "Auto-generate Doxygen documentation via Github Actions" -a + git push origin gh-pages + fi