Refactor documentation update workflow to separate token generation a… #464
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "Update Documentation" | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - arausell/docs-pr-auth | |
| workflow_dispatch: | |
| jobs: | |
| generate: | |
| runs-on: ubuntu-latest | |
| environment: documentation | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Generate Documentation | |
| uses: devcontainers/action@v1 | |
| with: | |
| generate-docs: "true" | |
| base-path-to-features: "./src" | |
| - name: Generate GitHub App Token | |
| id: generate_token | |
| uses: tibdex/github-app-token@v2.1.0 | |
| with: | |
| app_id: ${{ secrets.DEVCONTAINERS_APP_ID }} | |
| private_key: ${{ secrets.DEVCONTAINERS_APP_CLIENT_SECRET }} | |
| - name: Commit and Create PR for Documentation | |
| env: | |
| GH_TOKEN: ${{ steps.generate_token.outputs.token }} | |
| run: | | |
| set -e | |
| echo "Configuring Git..." | |
| git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git config --global user.name "github-actions[bot]" | |
| git config pull.rebase false | |
| branch="automated-documentation-update-${{ github.run_id }}" | |
| echo "Checking out new branch: $branch" | |
| git checkout -b "$branch" | |
| commit_message='Automated documentation update' | |
| pr_title='Automated documentation update' | |
| pr_body='Automated documentation update by the Devcontainers app.\\nThis PR includes updates to README.md files generated by the workflow.' | |
| echo "Adding updated README.md files..." | |
| # Assuming READMEs are updated within the src directory structure | |
| git add src/**/README.md | |
| echo "Checking for changes..." | |
| if git diff --staged --quiet; then | |
| echo "No changes to commit. Exiting." | |
| exit 0 | |
| fi | |
| echo "Committing changes..." | |
| git commit -m "$commit_message [skip ci]" | |
| echo "Pushing changes to origin/$branch..." | |
| git push origin "$branch" | |
| echo "Creating pull request..." | |
| gh pr create \\ | |
| --title "$pr_title" \\ | |
| --body "$pr_body" \\ | |
| --head "$branch" \\ | |
| --base "main" | |
| echo "Pull request created successfully." |