3-open-a-pull-request.yml (5896B)
1 name: Step 3 # Open a pull request 2 3 # Checks if the learner completed tasks for step 3. 4 # - Triggers when the user creates or edits the pull request. 5 # - Checks the pull request title and description. Adds a PR comment. 6 # - If all checks pass, the workflow is disabled so it doesn't run again. As such, workflow status badge will change to green. 7 8 on: 9 pull_request: 10 branches: 11 - main 12 types: 13 - opened 14 - synchronize 15 - reopened 16 - edited 17 18 permissions: 19 contents: read 20 actions: write 21 issues: write 22 23 env: 24 STEP_4_FILE: ".github/steps/4-merge-your-pull-request.md" 25 26 jobs: 27 find_exercise: 28 name: Find Exercise Issue 29 uses: skills/exercise-toolkit/.github/workflows/find-exercise-issue.yml@v0.1.0 30 31 check_step_work: 32 name: Check step work 33 runs-on: ubuntu-latest 34 needs: find_exercise 35 if: | 36 !github.event.repository.is_template && 37 github.head_ref == 'my-first-branch' 38 env: 39 ISSUE_URL: ${{ needs.find_exercise.outputs.issue-url }} 40 41 steps: 42 - name: Checkout 43 uses: actions/checkout@v4 44 45 - name: Get response templates 46 uses: actions/checkout@v4 47 with: 48 repository: skills/exercise-toolkit 49 path: exercise-toolkit 50 ref: v0.1.0 51 52 - name: Update comment - congratulate first PR 53 run: | 54 message="You've created your first pull request. Nice work! ✨🎉 Now, let's check your work." 55 gh issue comment "$ISSUE_URL" \ 56 --body "$message" \ 57 --edit-last 58 env: 59 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 60 61 - name: Check user work 62 id: check-user-work 63 run: | 64 # Checks to perform 65 checks='{ 66 "pr_title": { 67 "name": "Pull request title", 68 "passed": true, 69 "message": "" 70 }, 71 "pr_description": { 72 "name": "Pull request description", 73 "passed": true, 74 "message": "" 75 } 76 }' 77 78 # Check pull request title 79 if [ "${{ github.event.pull_request.title }}" != "Add my first file" ]; then 80 checks=$(echo $checks | jq '.pr_title.passed = false') 81 checks=$(echo $checks | jq '.pr_title.message = "Incorrect title"') 82 fi 83 84 # Check if a pull request description exists 85 if [ "${{ github.event.pull_request.body }}" == "" ]; then 86 checks=$(echo $checks | jq '.pr_description.passed = false') 87 checks=$(echo $checks | jq '.pr_description.message = "Empty pull request description"') 88 fi 89 90 # Verify all checks passed 91 passed=$(echo $checks | jq '. | all(.passed?)') 92 93 # Flatten to an array for returning. Allows iteration during rendering. 94 results=$(echo $checks | jq 'to_entries | map({name: .key} + .value)') 95 96 # Save pass status to output 97 echo "passed=$passed" >> $GITHUB_OUTPUT 98 99 # Save results to output 100 echo 'results<<EOF' >> $GITHUB_OUTPUT 101 echo $results >> $GITHUB_OUTPUT 102 echo 'EOF' >> $GITHUB_OUTPUT 103 104 - name: Build message - step results 105 id: build-message-step-results 106 uses: skills/action-text-variables@v1 107 with: 108 template-file: exercise-toolkit/markdown-templates/step-feedback/step-results.md 109 template-vars: '{ 110 "step_number": 3, 111 "passed": ${{ steps.check-user-work.outputs.passed }}, 112 "results_table": ${{ steps.check-user-work.outputs.results }}, 113 "tips": [ 114 "Issues are for capturing a problem/idea and possible solutions.", 115 "Pull requests are for active development and getting feedback." 116 ] 117 }' 118 119 - name: Create comment - step results 120 run: | 121 gh issue comment "$ISSUE_URL" \ 122 --body "${{ steps.build-message-step-results.outputs.updated-text }}" \ 123 --edit-last 124 env: 125 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 126 127 - name: Fail job if not all checks passed 128 if: steps.check-user-work.outputs.passed == 'false' 129 run: exit 1 130 131 - name: Build message - step finished 132 id: build-message-step-finish 133 uses: skills/action-text-variables@v1 134 with: 135 template-file: exercise-toolkit/markdown-templates/step-feedback/step-finished-prepare-next-step.md 136 template-vars: | 137 next_step_number=4 138 139 - name: Update comment - step finished 140 run: | 141 gh issue comment "$ISSUE_URL" \ 142 --body "${{ steps.build-message-step-finish.outputs.updated-text }}" 143 env: 144 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 145 146 post_step_4_content: 147 name: Post step 4 content 148 needs: [find_exercise, check_step_work] 149 runs-on: ubuntu-latest 150 env: 151 ISSUE_URL: ${{ needs.find_exercise.outputs.issue-url }} 152 153 steps: 154 - name: Checkout 155 uses: actions/checkout@v4 156 157 - name: Get response templates 158 uses: actions/checkout@v4 159 with: 160 repository: skills/exercise-toolkit 161 path: exercise-toolkit 162 ref: v0.1.0 163 164 - name: Create comment - add step content 165 run: | 166 gh issue comment "$ISSUE_URL" \ 167 --body-file ${{ env.STEP_4_FILE }} 168 env: 169 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 170 171 - name: Create comment - watching for progress 172 run: | 173 gh issue comment "$ISSUE_URL" \ 174 --body-file exercise-toolkit/markdown-templates/step-feedback/watching-for-progress.md 175 env: 176 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 177 178 - name: Disable current workflow and enable next one 179 run: | 180 gh workflow disable "Step 3" 181 gh workflow enable "Step 4" 182 env: 183 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}