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