|
| 1 | +name: Test SDK docs token |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - codex/test-sdk-docs-token-20260720122015 |
| 7 | + |
| 8 | +permissions: {} |
| 9 | + |
| 10 | +jobs: |
| 11 | + create-and-clean-up-demo2-pr: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Verify branch and pull-request access |
| 15 | + env: |
| 16 | + GH_TOKEN: ${{ secrets.GH_PAT }} |
| 17 | + TEST_BRANCH: automation/test-sdk-docs-token-${{ github.run_id }} |
| 18 | + run: | |
| 19 | + set -euo pipefail |
| 20 | + test -n "$GH_TOKEN" || { |
| 21 | + echo "::error::GH_PAT is not configured." |
| 22 | + exit 1 |
| 23 | + } |
| 24 | +
|
| 25 | + PR_NUMBER="" |
| 26 | + cleanup() { |
| 27 | + set +e |
| 28 | + if [ -n "$PR_NUMBER" ]; then |
| 29 | + gh pr close "$PR_NUMBER" --repo TextQLLabs/demo2 >/dev/null 2>&1 |
| 30 | + fi |
| 31 | + gh api --method DELETE \ |
| 32 | + "repos/TextQLLabs/demo2/git/refs/heads/${TEST_BRANCH}" \ |
| 33 | + >/dev/null 2>&1 |
| 34 | + } |
| 35 | + trap cleanup EXIT |
| 36 | +
|
| 37 | + MAIN_SHA=$(gh api repos/TextQLLabs/demo2/git/ref/heads/main --jq '.object.sha') |
| 38 | + gh api --method POST repos/TextQLLabs/demo2/git/refs \ |
| 39 | + -f ref="refs/heads/${TEST_BRANCH}" \ |
| 40 | + -f sha="$MAIN_SHA" >/dev/null |
| 41 | +
|
| 42 | + CONTENT=$(printf '%s\n' \ |
| 43 | + 'Temporary file used to verify SDK docs automation access.' \ |
| 44 | + | base64 -w 0) |
| 45 | + gh api --method PUT \ |
| 46 | + repos/TextQLLabs/demo2/contents/.github/sdk-docs-token-test.md \ |
| 47 | + -f message='test: verify SDK docs automation access' \ |
| 48 | + -f content="$CONTENT" \ |
| 49 | + -f branch="$TEST_BRANCH" >/dev/null |
| 50 | +
|
| 51 | + PR_URL=$(gh pr create \ |
| 52 | + --repo TextQLLabs/demo2 \ |
| 53 | + --base main \ |
| 54 | + --head "$TEST_BRANCH" \ |
| 55 | + --draft \ |
| 56 | + --title 'test: verify SDK docs automation access' \ |
| 57 | + --body 'Temporary automated test. This PR is closed and its branch deleted by the same workflow.') |
| 58 | + PR_NUMBER=${PR_URL##*/} |
| 59 | + echo "Successfully created ${PR_URL}; cleaning it up now." |
0 commit comments