diff --git a/.github/scripts/pushdocs.sh b/.github/scripts/pushdocs.sh index b1efc88..3d9ecc6 100755 --- a/.github/scripts/pushdocs.sh +++ b/.github/scripts/pushdocs.sh @@ -5,6 +5,10 @@ PAGES_REPO="ibm-verify.github.io" PAGES_BRANCH="main" DESTINATION_ROOT="${GITHUB_WORKSPACE}/docs" SOURCE_ROOT="${GITHUB_WORKSPACE}/monorepo" +TIMESTAMP=$(date +%Y%m%d%H%M%S) +BRANCH_NAME="feature/auto-pr-${{ github.run_id }}-${TIMESTAMP}" + +echo "Generated branch name: $BRANCH_NAME" # generate sdk docs and copy to respective locations for MODULE in `ls -d $SOURCE_ROOT/sdk/*` @@ -19,11 +23,37 @@ done cd ${SOURCE_ROOT} MESSAGE=`git log --format=%B -n 1` cd ${DESTINATION_ROOT} + +# suppress GH token in the authorization header. # thanks to https://stackoverflow.com/a/64271581/5099773 git config -l | grep 'http\..*\.extraheader' | cut -d= -f1 | \ xargs -L1 git config --unset-all + +# set up git config git config user.email "shankarv@sg.ibm.com" git config user.name "shankarv" + +# switch to a feature branch +git checkout -b $BRANCH_NAME + +# commit changes git add -A -git diff-index --quiet HEAD || git commit -m "${MESSAGE}" -git push -u https://${PAGES_USER}:${GH_PAGES_TOKEN}@github.com/${PAGES_USER}/${PAGES_REPO} +git commit -m "${MESSAGE}" +git status + +# push to repo +git push -u origin $BRANCH_NAME + +# create a PR +gh pr create \ + --body "" \ + --title "docs(auto): update documentation" \ + --head "$BRANCH_NAME" \ + --base "master" + +# git config --get remote.origin.url +# git remote set-url origin https://${{ secrets.GH_PAGES_TOKEN }}@github.com/${PAGES_USER}/${PAGES_REPO} +# git push origin +# git config --get remote.origin.url + +# git push -u https://${PAGES_USER}:${GH_PAGES_TOKEN}@github.com/${PAGES_USER}/${PAGES_REPO} diff --git a/.github/workflows/pushdocs.yml b/.github/workflows/pushdocs.yml index 3a1ed2e..972a021 100644 --- a/.github/workflows/pushdocs.yml +++ b/.github/workflows/pushdocs.yml @@ -35,6 +35,12 @@ jobs: with: node-version: '12' + - name: Authorize GitHub CLI + env: + GITHUB_TOKEN: ${{ secrets.GH_PAGES_API_TOKEN }} + run: | + gh auth login --with-token <<< "$GITHUB_TOKEN" + - name: Push docs run: ${{ github.workspace }}/monorepo/.github/scripts/pushdocs.sh shell: bash