name: Reset Progress on: issues: types: [opened, labeled] permissions: contents: write issues: write jobs: get_current_step: name: Check current step number runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Check step file existence run: | if [ -f ./.github/steps/-step.txt ]; then echo "Step file exists. Contents:"; cat ./.github/steps/-step.txt; else echo "Step file does not exist."; fi - id: get_step run: | echo "current_step=$(cat ./.github/steps/-step.txt)" >> $GITHUB_OUTPUT outputs: current_step: ${{ steps.get_step.outputs.current_step }} reset_quest: needs: get_current_step if: >- ${{ github.event_name == 'issues' && (contains(github.event.issue.title, 'Reset') || contains(github.event.issue.title, 'Skip') || contains(join(github.event.issue.labels.*.name, ''), 'reset'))}} runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Debug event payload run: | echo "Event name: ${{ github.event_name }}" echo "Event labels: ${{ toJson(github.event.issue.labels) }}" echo "Event title: ${{ github.event.issue.title }}" - name: Debug issue labels run: | echo "Issue labels: ${{ toJson(github.event.issue.labels) }}" - name: Reset to step 0 uses: skills/action-update-step@v2 with: token: ${{ secrets.GITHUB_TOKEN }} from_step: ${{ needs.get_current_step.outputs.current_step }} to_step: 0 - name: Rewrite badge links in README.md to absolute URLs run: | OWNER_REPO="${GITHUB_REPOSITORY}" # Use pipe as delimiter and target the specific pattern ](/issues/new? # This replaces relative issue links like ](/issues/new?...) with absolute ones sed -i 's|](/issues/new?|](https://github.com/'"${OWNER_REPO}"'/issues/new?|g' README.md # Fix any malformed issue links that include blob/main in the path sed -i "s#github.com/${OWNER_REPO}/blob/main/issues/new?#github.com/${OWNER_REPO}/issues/new?#g" README.md - name: Comment and close issue uses: actions/github-script@v7 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: "Your progress has been reset! You can now select a new user quest from the [Welcome step](https://github.com/${context.repo.owner}/${context.repo.repo}/blob/main/README.md)." }); github.rest.issues.update({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, state: 'closed' });