|
| 1 | +name: Step 0 |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + actions: write |
| 11 | + issues: write |
| 12 | + |
| 13 | +env: |
| 14 | + STEP_1_FILE: ".github/steps/1-resolve-duplicate-issues.md" |
| 15 | + |
| 16 | +jobs: |
| 17 | + start_exercise: |
| 18 | + if: | |
| 19 | + !github.event.repository.is_template |
| 20 | + name: Start Exercise |
| 21 | + uses: skills/exercise-toolkit/.github/workflows/[email protected] |
| 22 | + with: |
| 23 | + exercise-title: "Connect the Dots" |
| 24 | + intro-message: "Let's learn to navigate a GitHub repository effectively!" |
| 25 | + |
| 26 | + create_first_task: |
| 27 | + name: Create first task |
| 28 | + runs-on: ubuntu-latest |
| 29 | + needs: [start_exercise] |
| 30 | + env: |
| 31 | + ISSUE_URL: ${{ needs.start_exercise.outputs.issue-url }} |
| 32 | + outputs: |
| 33 | + original_issue: ${{ steps.issue_a.outputs.original_issue }} |
| 34 | + duplicate_issue: ${{ steps.issue_b.outputs.duplicate_issue }} |
| 35 | + |
| 36 | + steps: |
| 37 | + - name: Checkout |
| 38 | + uses: actions/checkout@v4 |
| 39 | + |
| 40 | + - name: Create 'Fix broken sidebar' issue (target for duplicate) |
| 41 | + id: issue_a |
| 42 | + uses: actions/github-script@v7 |
| 43 | + with: |
| 44 | + result-encoding: string |
| 45 | + script: | |
| 46 | + const { data: issue } = await github.rest.issues.create({ |
| 47 | + owner: context.repo.owner, |
| 48 | + repo: context.repo.repo, |
| 49 | + title: "Fix the broken sidebar", |
| 50 | + body: "The sidebar in `docs/_sidebar.md` is broken and needs fixing." |
| 51 | + }); |
| 52 | + core.setOutput("original_issue", issue.number); |
| 53 | +
|
| 54 | + - name: Create 'Duplicate report' issue (to be closed as duplicate) |
| 55 | + id: issue_b |
| 56 | + uses: actions/github-script@v7 |
| 57 | + with: |
| 58 | + result-encoding: string |
| 59 | + script: | |
| 60 | + const { data: issue } = await github.rest.issues.create({ |
| 61 | + owner: context.repo.owner, |
| 62 | + repo: context.repo.repo, |
| 63 | + title: "Sidebar bug again", |
| 64 | + body: "Looks like the sidebar bug was already reported." |
| 65 | + }); |
| 66 | + core.setOutput("duplicate_issue", issue.number); |
| 67 | +
|
| 68 | +
|
| 69 | + prep_repo_content: |
| 70 | + name: Prep repo for next step |
| 71 | + runs-on: ubuntu-latest |
| 72 | + needs: [start_exercise, create_first_task] |
| 73 | + env: |
| 74 | + ISSUE_URL: ${{ needs.start_exercise.outputs.issue-url }} |
| 75 | + |
| 76 | + steps: |
| 77 | + - name: Checkout |
| 78 | + uses: actions/checkout@v4 |
| 79 | + |
| 80 | + - name: Prepare files history |
| 81 | + run: | |
| 82 | + echo "Make sure we are on step 0" |
| 83 | + if [ "${{ github.workflow }}" != "Step 0" ] |
| 84 | + then |
| 85 | + echo "Current step is not Step 0" |
| 86 | + exit 0 |
| 87 | + fi |
| 88 | + git config user.name github-actions[bot] |
| 89 | + git config user.email github-actions[bot]@users.noreply.github.com |
| 90 | + git checkout main |
| 91 | + echo "Update _sidebar.md for the 1st time" |
| 92 | + cp -f .github/files/_sidebar01.md docs/_sidebar.md |
| 93 | + git add docs/_sidebar.md |
| 94 | + git commit -m "updated _sidebar.md" |
| 95 | + git pull --rebase origin main || true |
| 96 | + git push || true |
| 97 | + echo "update _sidebar.md for the 2nd time" |
| 98 | + cp -f .github/files/_sidebar02.md docs/_sidebar.md |
| 99 | + git add docs/_sidebar.md |
| 100 | + git commit -m "add sidebar to documentation" |
| 101 | + git push |
| 102 | + echo "preserve the commit shaw" |
| 103 | + git log --all --oneline | grep "add sidebar to documentation" | cut -c 1-7 >> .github/files/SIDEBARCOMMIT |
| 104 | + git add .github/files/SIDEBARCOMMIT |
| 105 | + git commit -m "created SIDEBARCOMMIT" |
| 106 | + git push |
| 107 | + env: |
| 108 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 109 | + |
| 110 | + post_next_step_content: |
| 111 | + name: Post next step content |
| 112 | + runs-on: ubuntu-latest |
| 113 | + needs: [start_exercise, create_first_task] |
| 114 | + env: |
| 115 | + ISSUE_URL: ${{ needs.start_exercise.outputs.issue-url }} |
| 116 | + |
| 117 | + steps: |
| 118 | + - name: Checkout |
| 119 | + uses: actions/checkout@v4 |
| 120 | + |
| 121 | + - name: Get response templates |
| 122 | + uses: actions/checkout@v4 |
| 123 | + with: |
| 124 | + repository: skills/exercise-toolkit |
| 125 | + path: exercise-toolkit |
| 126 | + ref: v0.3.0 |
| 127 | + |
| 128 | + - name: Build comment - add step content |
| 129 | + id: build-comment |
| 130 | + uses: skills/action-text-variables@v1 |
| 131 | + with: |
| 132 | + template-file: ${{ env.STEP_1_FILE }} |
| 133 | + template-vars: | |
| 134 | + full_repo_name=${{ github.repository }} |
| 135 | + original_issue=${{ needs.create_first_task.outputs.original_issue }} |
| 136 | + duplicate_issue=${{ needs.create_first_task.outputs.duplicate_issue }} |
| 137 | +
|
| 138 | + - name: Create comment - add step content |
| 139 | + run: | |
| 140 | + gh issue comment "$ISSUE_URL" \ |
| 141 | + --body "$ISSUE_BODY" |
| 142 | + env: |
| 143 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 144 | + ISSUE_BODY: ${{ steps.build-comment.outputs.updated-text }} |
| 145 | + |
| 146 | + - name: Create comment - watching for progress |
| 147 | + run: | |
| 148 | + gh issue comment "$ISSUE_URL" \ |
| 149 | + --body-file exercise-toolkit/markdown-templates/step-feedback/watching-for-progress.md |
| 150 | + env: |
| 151 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 152 | + |
| 153 | + - name: Enable next step workflow |
| 154 | + run: | |
| 155 | + gh workflow enable "Step 1" |
| 156 | + env: |
| 157 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments