Skip to content

Add my first file

Add my first file #1

name: Step 3 # Open a pull request
# Checks if the learner completed tasks for step 3.
# - Triggers when the user creates or edits the pull request.
# - Checks the pull request title and description. Adds a PR comment.
# - If all checks pass, the workflow is disabled so it doesn't run again. As such, workflow status badge will change to green.
on:
pull_request:
branches:
- main
types:
- opened
- synchronize
- reopened
- edited
permissions:
contents: read
actions: write
issues: write
env:
STEP_4_FILE: ".github/steps/4-merge-your-pull-request.md"
jobs:
find_exercise:
name: Find Exercise Issue
uses: skills/exercise-toolkit/.github/workflows/[email protected]
check_step_work:
name: Check step work
runs-on: ubuntu-latest
needs: find_exercise
if: |
!github.event.repository.is_template &&
github.head_ref == 'my-first-branch'
env:
ISSUE_URL: ${{ needs.find_exercise.outputs.issue-url }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get response templates
uses: actions/checkout@v4
with:
repository: skills/exercise-toolkit
path: exercise-toolkit
ref: v0.1.0
- name: Update comment - congratulate first PR
run: |
message="You've created your first pull request. Nice work! ✨🎉 Now, let's check your work."
gh issue comment "$ISSUE_URL" \
--body "$message" \
--edit-last
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check user work
id: check-user-work
run: |
# Checks to perform
checks='{
"pr_title": {
"name": "Pull request title",
"passed": true,
"message": ""
},
"pr_description": {
"name": "Pull request description",
"passed": true,
"message": ""
}
}'
# Check pull request title
if [ "${{ github.event.pull_request.title }}" != "Add my first file" ]; then
checks=$(echo $checks | jq '.pr_title.passed = false')
checks=$(echo $checks | jq '.pr_title.message = "Incorrect title"')
fi
# Check if a pull request description exists
if [ "${{ github.event.pull_request.body }}" == "" ]; then
checks=$(echo $checks | jq '.pr_description.passed = false')
checks=$(echo $checks | jq '.pr_description.message = "Empty pull request description"')
fi
# Verify all checks passed
passed=$(echo $checks | jq '. | all(.passed?)')
# Flatten to an array for returning. Allows iteration during rendering.
results=$(echo $checks | jq 'to_entries | map({name: .key} + .value)')
# Save pass status to output
echo "passed=$passed" >> $GITHUB_OUTPUT
# Save results to output
echo 'results<<EOF' >> $GITHUB_OUTPUT
echo $results >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
- name: Build message - step results
id: build-message-step-results
uses: skills/action-text-variables@v1
with:
template-file: exercise-toolkit/markdown-templates/step-feedback/step-results.md
template-vars: '{
"step_number": 3,
"passed": ${{ steps.check-user-work.outputs.passed }},
"results_table": ${{ steps.check-user-work.outputs.results }},
"tips": [
"Issues are for capturing a problem/idea and possible solutions.",
"Pull requests are for active development and getting feedback."
]
}'
- name: Create comment - step results
run: |
gh issue comment "$ISSUE_URL" \
--body "${{ steps.build-message-step-results.outputs.updated-text }}" \
--edit-last
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Fail job if not all checks passed
if: steps.check-user-work.outputs.passed == 'false'
run: exit 1
- name: Build message - step finished
id: build-message-step-finish
uses: skills/action-text-variables@v1
with:
template-file: exercise-toolkit/markdown-templates/step-feedback/step-finished-prepare-next-step.md
template-vars: |
next_step_number=4
- name: Update comment - step finished
run: |
gh issue comment "$ISSUE_URL" \
--body "${{ steps.build-message-step-finish.outputs.updated-text }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
post_step_4_content:
name: Post step 4 content
needs: [find_exercise, check_step_work]
runs-on: ubuntu-latest
env:
ISSUE_URL: ${{ needs.find_exercise.outputs.issue-url }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get response templates
uses: actions/checkout@v4
with:
repository: skills/exercise-toolkit
path: exercise-toolkit
ref: v0.1.0
- name: Create comment - add step content
run: |
gh issue comment "$ISSUE_URL" \
--body-file ${{ env.STEP_4_FILE }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create comment - watching for progress
run: |
gh issue comment "$ISSUE_URL" \
--body-file exercise-toolkit/markdown-templates/step-feedback/watching-for-progress.md
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Disable current workflow and enable next one
run: |
gh workflow disable "Step 3"
gh workflow enable "Step 4"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}