feat: optional tour for first-time users #147
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Add New Institution | |
| on: | |
| issues: | |
| types: [opened, reopened] | |
| jobs: | |
| add-qrcode: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.issue.number }} | |
| cancel-in-progress: true | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Check for [addQR] Keyword | |
| id: check_keyword | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const issueTitle = context.payload.issue.title; | |
| const issueBody = context.payload.issue.body || ''; | |
| if (!issueTitle.includes('[addQR]') && !issueBody.includes('[addQR]')) { | |
| core.setFailed('No [addQR] keyword found. Exiting workflow.'); | |
| return process.exit(78); | |
| } | |
| console.log('Keyword [addQR] found. Proceeding with workflow.'); | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4.2.0 | |
| with: | |
| node-version: "18" | |
| - name: Install Dependencies | |
| run: | | |
| npm install axios --legacy-peer-deps | |
| - name: Create Input File | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| // Safely write issue body to file | |
| fs.writeFileSync('input.data', context.payload.issue.body || ''); | |
| console.log('Input file created successfully'); | |
| - name: Run Extract Fields Script | |
| id: extract | |
| run: | | |
| echo "${{ github.event.issue.number }}" | |
| node actions/extractFields.js | |
| env: | |
| INPUT_FILE: "input.data" | |
| ISSUE_ID: "${{ github.event.issue.number }}" | |
| - name: Set Environment Variables | |
| id: set_env | |
| run: | | |
| if [ -f "extractedFields.json" ]; then | |
| # Read the JSON file and set environment variables | |
| TYPE_OF_INSTITUTE=$(jq -r '.typeOfInstitute // "N/A"' extractedFields.json) | |
| NAME_OF_THE_MASJID=$(jq -r '.nameOfTheMasjid // "N/A"' extractedFields.json) | |
| NAME_OF_THE_CITY=$(jq -r '.nameOfTheCity // "N/A"' extractedFields.json) | |
| STATE=$(jq -r '.state // "N/A"' extractedFields.json) | |
| NEXT_ID=$(jq -r '.nextId // "N/A"' extractedFields.json) | |
| QR_CODE_IMAGE=$(jq -r '.qrCodeImage // "N/A"' extractedFields.json) | |
| REMARKS=$(jq -r '.remarks // "N/A"' extractedFields.json) | |
| QR_DECODE_STATUS=$(jq -r '.qrDecodeStatus // "FAILED"' extractedFields.json) | |
| QR_DECODE_ATTEMPTS=$(jq -r '.qrDecodeAttempts // "0"' extractedFields.json) | |
| QR_CONTENT=$(jq -r '.qrContent // "Not decoded"' extractedFields.json) | |
| # Set environment variables for subsequent steps | |
| echo "TYPE_OF_INSTITUTE=$TYPE_OF_INSTITUTE" >> $GITHUB_ENV | |
| echo "NAME_OF_THE_MASJID=$NAME_OF_THE_MASJID" >> $GITHUB_ENV | |
| echo "NAME_OF_THE_CITY=$NAME_OF_THE_CITY" >> $GITHUB_ENV | |
| echo "STATE=$STATE" >> $GITHUB_ENV | |
| echo "NEXT_ID=$NEXT_ID" >> $GITHUB_ENV | |
| echo "QR_CODE_IMAGE=$QR_CODE_IMAGE" >> $GITHUB_ENV | |
| echo "REMARKS=$REMARKS" >> $GITHUB_ENV | |
| echo "QR_DECODE_STATUS=$QR_DECODE_STATUS" >> $GITHUB_ENV | |
| echo "QR_DECODE_ATTEMPTS=$QR_DECODE_ATTEMPTS" >> $GITHUB_ENV | |
| echo "QR_CONTENT=$QR_CONTENT" >> $GITHUB_ENV | |
| else | |
| echo "extractedFields.json not found" | |
| exit 1 | |
| fi | |
| - name: Append Data to institutions.ts | |
| id: append | |
| run: | | |
| node actions/append_institution.js | |
| env: | |
| TYPE_OF_INSTITUTE: ${{ env.TYPE_OF_INSTITUTE }} | |
| NAME_OF_THE_MASJID: ${{ env.NAME_OF_THE_MASJID }} | |
| NAME_OF_THE_CITY: ${{ env.NAME_OF_THE_CITY }} | |
| STATE: ${{ env.STATE }} | |
| NEXT_ID: ${{ env.NEXT_ID }} | |
| QR_CODE_IMAGE: ${{ env.QR_CODE_IMAGE }} | |
| REMARKS: ${{ env.REMARKS }} | |
| QR_DECODE_STATUS: ${{ env.QR_DECODE_STATUS }} | |
| QR_DECODE_ATTEMPTS: ${{ env.QR_DECODE_ATTEMPTS }} | |
| QR_CONTENT: ${{ env.QR_CONTENT }} | |
| - name: Update QR Code Status | |
| id: update_qr_status | |
| run: | | |
| # Read the last added institution from institutions.ts | |
| LAST_INSTITUTION=$(grep -A 10 "qrContent:" app/data/institutions.ts | tail -n 10) | |
| # Extract QR content and status | |
| if echo "$LAST_INSTITUTION" | grep -q "qrContent:"; then | |
| QR_CONTENT=$(echo "$LAST_INSTITUTION" | grep "qrContent:" | cut -d'"' -f2) | |
| echo "QR_CONTENT=$QR_CONTENT" >> $GITHUB_ENV | |
| echo "QR_DECODE_STATUS=SUCCESS" >> $GITHUB_ENV | |
| echo "QR_DECODE_ATTEMPTS=1" >> $GITHUB_ENV | |
| else | |
| echo "QR_DECODE_STATUS=FAILED" >> $GITHUB_ENV | |
| echo "QR_DECODE_ATTEMPTS=0" >> $GITHUB_ENV | |
| echo "QR_CONTENT=Not decoded" >> $GITHUB_ENV | |
| fi | |
| - name: Show Git Diff | |
| run: | | |
| echo "Displaying git diff for changes in institutions.ts" | |
| git diff app/data/institutions.ts | |
| rm -rf extractedFields.json input.data | |
| git checkout package.json | |
| - name: Get Issue Author Details | |
| id: author | |
| run: | | |
| AUTHOR_NAME=$(gh api /users/${{ github.event.issue.user.login }} --jq .name) | |
| AUTHOR_EMAIL=$(gh api /users/${{ github.event.issue.user.login }} --jq .email) | |
| AUTHOR_LOGIN="${{ github.event.issue.user.login }}" | |
| if [ "$AUTHOR_NAME" = "" ]; then | |
| AUTHOR_NAME="${AUTHOR_LOGIN}" | |
| fi | |
| if [ "$AUTHOR_EMAIL" = "" ]; then | |
| AUTHOR_EMAIL="${AUTHOR_LOGIN}@users.noreply.github.com" | |
| fi | |
| echo "name=$AUTHOR_NAME" >> $GITHUB_OUTPUT | |
| echo "email=$AUTHOR_EMAIL" >> $GITHUB_OUTPUT | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create, Commit, and Push New Branch | |
| id: create_branch | |
| run: | | |
| BRANCH_NAME="add-institution-${{ github.event.issue.number }}" | |
| echo "Creating branch: $BRANCH_NAME" | |
| # Check if branch exists remotely | |
| if git ls-remote --heads origin "$BRANCH_NAME" | grep -q "$BRANCH_NAME"; then | |
| echo "Branch $BRANCH_NAME already exists. Deleting it..." | |
| git push origin --delete "$BRANCH_NAME" | |
| fi | |
| # Create and switch to new branch | |
| git checkout -b "$BRANCH_NAME" | |
| git config --global user.name "${{ steps.author.outputs.name }}" | |
| git config --global user.email "${{ steps.author.outputs.email }}" | |
| git add app/data/institutions.ts | |
| git commit -m ":memo: add new institution from #${{ github.event.issue.number }}" | |
| echo "Pushing branch $BRANCH_NAME to origin..." | |
| git push origin "$BRANCH_NAME" --verbose | |
| echo "branch=$BRANCH_NAME" >> $GITHUB_OUTPUT | |
| - name: Create Pull Request | |
| uses: actions/github-script@v7 | |
| id: create-pr | |
| with: | |
| script: | | |
| const { owner, repo } = context.repo; | |
| const issueNumber = context.payload.issue.number; | |
| const prBody = `Closes #${issueNumber}\n\n## Appended Institution Details\n- Type: ${process.env.TYPE_OF_INSTITUTE || 'N/A'}\n- Name: ${process.env.NAME_OF_THE_MASJID || 'N/A'}\n- City: ${process.env.NAME_OF_THE_CITY || 'N/A'}\n- State: ${process.env.STATE || 'N/A'}\n- Generated ID: ${process.env.NEXT_ID || 'N/A'}\n- QR Image URL: ${process.env.QR_CODE_IMAGE || 'N/A'}\n- Remarks: ${process.env.REMARKS || 'N/A'}\n- Issue ID: ${issueNumber}\n\n## QR Code Status\n- Status: ${process.env.QR_DECODE_STATUS || 'FAILED'}\n- Attempts: ${process.env.QR_DECODE_ATTEMPTS || '0'}\n- QR Content: ${process.env.QR_CONTENT || 'Not decoded'}\n\n${process.env.QR_DECODE_STATUS === 'FAILED' ? `## Manual QR Content Input\nPlease provide the QR content in the following format:\n<!-- QR_CONTENT: [content] -->` : ''}\n\nAutomated PR created by the Add New Institution workflow.`; | |
| try { | |
| const pr = await github.rest.pulls.create({ | |
| owner, | |
| repo, | |
| title: `:memo: add new institution from #${issueNumber}`, | |
| body: prBody, | |
| head: `add-institution-${issueNumber}`, | |
| base: 'main' | |
| }); | |
| // Add labels to the PR | |
| await github.rest.issues.addLabels({ | |
| owner, | |
| repo, | |
| issue_number: pr.data.number, | |
| labels: ['new-institution', 'automated-pr'] | |
| }); | |
| console.log(`PR created: ${pr.data.html_url}`); | |
| return pr.data.number; | |
| } catch (error) { | |
| core.setFailed(`Failed to create PR: ${error.message}`); | |
| throw error; | |
| } | |
| - name: Comment on Issue | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const issueNumber = context.payload.issue.number; | |
| const prNumber = process.env.PR_NUMBER; | |
| await github.rest.issues.createComment({ | |
| ...context.repo, | |
| issue_number: issueNumber, | |
| body: `Thank you for your contribution! A PR has been created #${prNumber} to add this institution.` | |
| }); | |
| env: | |
| PR_NUMBER: ${{ steps.create-pr.outputs.result }} |