|
| 1 | +name: Step 1, Create a pull request |
| 2 | + |
| 3 | +# This step triggers after the learner creates a pull request for the my-resume branch |
| 4 | +# This workflow updates from step 1 to step 2. |
| 5 | + |
| 6 | +# This will run every time we open a pull request. |
| 7 | +# Reference: https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows |
| 8 | +on: |
| 9 | + workflow_dispatch: |
| 10 | + pull_request: |
| 11 | + types: [opened] |
| 12 | + |
| 13 | +# Reference: https://docs.github.com/en/actions/security-guides/automatic-token-authentication |
| 14 | +permissions: |
| 15 | + # Need `contents: read` to checkout the repository. |
| 16 | + # Need `contents: write` to update the step metadata. |
| 17 | + contents: write |
| 18 | + |
| 19 | +jobs: |
| 20 | + # Get the current step to only run the main job when the learner is on the same step. |
| 21 | + get_current_step: |
| 22 | + name: Check current step number |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - name: Checkout |
| 26 | + uses: actions/checkout@v4 |
| 27 | + - id: get_step |
| 28 | + run: | |
| 29 | + echo "current_step=$(cat ./.github/steps/-step.txt)" >> $GITHUB_OUTPUT |
| 30 | + outputs: |
| 31 | + current_step: ${{ steps.get_step.outputs.current_step }} |
| 32 | + |
| 33 | + on_create_pr: |
| 34 | + name: On create PR |
| 35 | + needs: get_current_step |
| 36 | + |
| 37 | + # We will only run this action when: |
| 38 | + # 1. This repository isn't the template repository. |
| 39 | + # 2. The step is currently 1. |
| 40 | + # Reference: https://docs.github.com/en/actions/learn-github-actions/contexts |
| 41 | + # Reference: https://docs.github.com/en/actions/learn-github-actions/expressions |
| 42 | + if: >- |
| 43 | + ${{ !github.event.repository.is_template |
| 44 | + && needs.get_current_step.outputs.current_step == 1 }} |
| 45 | +
|
| 46 | + # We'll run Ubuntu for performance instead of Mac or Windows. |
| 47 | + runs-on: ubuntu-latest |
| 48 | + |
| 49 | + steps: |
| 50 | + # We'll need to check out the repository so that we can edit the README. |
| 51 | + - name: Checkout |
| 52 | + uses: actions/checkout@v4 |
| 53 | + with: |
| 54 | + fetch-depth: 0 # Let's get all the branches. |
| 55 | + |
| 56 | + - name: Prepare a merge conflict |
| 57 | + run: | |
| 58 | + echo "Make sure we are on step 1" |
| 59 | + if [ "$(cat .github/steps/-step.txt)" != 1 ] |
| 60 | + then |
| 61 | + echo "Current step is not 1" |
| 62 | + exit 0 |
| 63 | + fi |
| 64 | +
|
| 65 | + echo "Manually update step in my-resume to match step in main branch" |
| 66 | + git checkout my-resume |
| 67 | + git config user.name github-actions[bot] |
| 68 | + git config user.email github-actions[bot]@users.noreply.github.com |
| 69 | + sed -i.bak 's/1/2/' .github/steps/-step.txt |
| 70 | + git add .github/steps/-step.txt |
| 71 | + git commit --message="Update step in my-resume" |
| 72 | + echo "Push" |
| 73 | + git push origin my-resume |
| 74 | +
|
| 75 | + echo "Create a merge conflict in main" |
| 76 | + git checkout main |
| 77 | + sed -i.bak 's/Experience/Jobs/' resume.md |
| 78 | + git add resume.md |
| 79 | + git commit --message="Update resume.md in main" |
| 80 | +
|
| 81 | + echo "Push" |
| 82 | + git push origin main |
| 83 | + env: |
| 84 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 85 | + |
| 86 | + # In README.md, switch step 1 for step 2. |
| 87 | + - name: Update to step 2 |
| 88 | + uses: skills/action-update-step@v2 |
| 89 | + with: |
| 90 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 91 | + from_step: 1 |
| 92 | + to_step: 2 |
| 93 | + branch_name: my-resume |
0 commit comments