|
| 1 | +name: Step 4a # Copilot on GitHub |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + types: |
| 8 | + - closed |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + actions: write |
| 13 | + issues: write |
| 14 | + |
| 15 | +env: |
| 16 | + REVIEW_FILE: ".github/steps/x-review.md" |
| 17 | + |
| 18 | +jobs: |
| 19 | + find_exercise: |
| 20 | + if: | |
| 21 | + !github.event.repository.is_template |
| 22 | + name: Find exercise by issue title |
| 23 | + runs-on: ubuntu-latest |
| 24 | + |
| 25 | + outputs: |
| 26 | + issue-url: ${{ steps.get-issue-url.outputs.ISSUE_URL }} |
| 27 | + |
| 28 | + steps: |
| 29 | + - id: get-issue-url |
| 30 | + run: | |
| 31 | + # Get the issue url from the event or search for it. |
| 32 | + if [ -n "${{ github.event.issue }}" ]; then |
| 33 | + issue_url="${{ github.event.issue.html_url }}" |
| 34 | + else |
| 35 | + issue_url=$(gh issue list --repo $REPO --search "in:title Exercise:" --json url,title --jq '.[].url') |
| 36 | + fi |
| 37 | +
|
| 38 | + # Save to output |
| 39 | + echo "ISSUE_URL=$issue_url" >> $GITHUB_OUTPUT |
| 40 | + env: |
| 41 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 42 | + REPO: ${{ github.repository }} |
| 43 | + |
| 44 | + check_step_work: |
| 45 | + name: Check step work |
| 46 | + runs-on: ubuntu-latest |
| 47 | + needs: [find_exercise] |
| 48 | + env: |
| 49 | + ISSUE_URL: ${{ needs.find_exercise.outputs.issue-url }} |
| 50 | + |
| 51 | + steps: |
| 52 | + - name: Checkout |
| 53 | + uses: actions/checkout@v4 |
| 54 | + |
| 55 | + - name: Get response templates |
| 56 | + uses: actions/checkout@v4 |
| 57 | + with: |
| 58 | + repository: skills/response-templates |
| 59 | + path: skills-response-templates |
| 60 | + |
| 61 | + # START: Check practical exercise |
| 62 | + |
| 63 | + # Nothing to check. Merging the pull request is enough. |
| 64 | + |
| 65 | + # END: Check practical exercise |
| 66 | + |
| 67 | + - name: Create comment - step finished - final review next |
| 68 | + run: | |
| 69 | + gh issue comment "$ISSUE_URL" \ |
| 70 | + --body-file skills-response-templates/step-feedback/lesson-review.md |
| 71 | + env: |
| 72 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 73 | + |
| 74 | + post_review_content: |
| 75 | + name: Post review content |
| 76 | + needs: [find_exercise, check_step_work] |
| 77 | + runs-on: ubuntu-latest |
| 78 | + env: |
| 79 | + ISSUE_URL: ${{ needs.find_exercise.outputs.issue-url }} |
| 80 | + |
| 81 | + steps: |
| 82 | + - name: Checkout |
| 83 | + uses: actions/checkout@v4 |
| 84 | + |
| 85 | + - name: Get response templates |
| 86 | + uses: actions/checkout@v4 |
| 87 | + with: |
| 88 | + repository: skills/response-templates |
| 89 | + path: skills-response-templates |
| 90 | + |
| 91 | + - name: Create comment - add step content |
| 92 | + run: | |
| 93 | + gh issue comment "$ISSUE_URL" \ |
| 94 | + --body-file "$REVIEW_FILE" |
| 95 | + env: |
| 96 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 97 | + |
| 98 | + finish_exercise: |
| 99 | + name: Finish exercise |
| 100 | + needs: [find_exercise, post_review_content] |
| 101 | + runs-on: ubuntu-latest |
| 102 | + env: |
| 103 | + ISSUE_URL: ${{ needs.find_exercise.outputs.issue-url }} |
| 104 | + |
| 105 | + steps: |
| 106 | + - name: Checkout |
| 107 | + uses: actions/checkout@v4 |
| 108 | + with: |
| 109 | + ref: main |
| 110 | + |
| 111 | + - name: Get response templates |
| 112 | + uses: actions/checkout@v4 |
| 113 | + with: |
| 114 | + repository: skills/response-templates |
| 115 | + path: skills-response-templates |
| 116 | + |
| 117 | + - name: Configure Git user |
| 118 | + run: | |
| 119 | + git config user.name github-actions[bot] |
| 120 | + git config user.email github-actions[bot]@users.noreply.github.com |
| 121 | +
|
| 122 | + - name: Build message - congratulations |
| 123 | + id: build-message-congratulations |
| 124 | + uses: skills/action-text-variables@v1 |
| 125 | + with: |
| 126 | + template-file: skills-response-templates/readme/congratulations.md |
| 127 | + template-vars: | |
| 128 | + login=${{ github.actor }} |
| 129 | +
|
| 130 | + - name: Update README - congratulations |
| 131 | + run: | |
| 132 | + # Add "Congratulations" to the start of the README |
| 133 | + orig_readme=$(cat README.md) |
| 134 | + new_readme="${{ steps.build-message-congratulations.outputs.updated-text }} $orig_readme" |
| 135 | +
|
| 136 | + # Update file and push |
| 137 | + echo "$new_readme" > README.md |
| 138 | + git add README.md |
| 139 | + git commit --message="Congratulations!🎉" |
| 140 | + git push |
| 141 | + env: |
| 142 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 143 | + |
| 144 | + - name: Build message - exercise finished |
| 145 | + id: build-finish-message |
| 146 | + uses: skills/action-text-variables@v1 |
| 147 | + with: |
| 148 | + template-file: skills-response-templates/step-feedback/lesson-finished.md |
| 149 | + template-vars: | |
| 150 | + login=${{ github.actor }} |
| 151 | + repo_full_name=${{ github.repository }} |
| 152 | +
|
| 153 | + - name: Create comment - exercise finished |
| 154 | + run: | |
| 155 | + gh issue comment "$ISSUE_URL" \ |
| 156 | + --body "$ISSUE_BODY" |
| 157 | + env: |
| 158 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 159 | + ISSUE_BODY: ${{ steps.build-finish-message.outputs.updated-text }} |
| 160 | + |
| 161 | + - name: Close issue |
| 162 | + run: gh issue close "$ISSUE_URL" |
| 163 | + env: |
| 164 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 165 | + |
| 166 | + - name: Disable current workflow |
| 167 | + run: | |
| 168 | + gh workflow disable "Step 4a" |
| 169 | + gh workflow disable "Step 4b" |
| 170 | + env: |
| 171 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments