OpenSourceFellows / amplify

Open Source Fellow Sandbox
https://amplify-app-production.herokuapp.com/
MIT License
85 stars 60 forks source link

Spellcheck Action #626

Open eprice555 opened 11 months ago

eprice555 commented 11 months ago

Part of the OSS Architecture track

User Story: To create a spellcheck GitHub Action like the austenstone/spellchecker-cli-action-summary action, you can use a spellchecking library like cspell or codespell, and use the actions/github-script action to post a summary of the spellcheck results as a comment on the pull request.

Task

Suggestions: try this prompt with Copilot: "how to create a spellcheck GitHub Action like this one https://github.com/austenstone/spellchecker-cli-action-summary"

or debug the following output:

Directions: Here's an example of how to create a spellcheck GitHub Action that posts a summary of the spellcheck results as a comment on the pull request:

Create a new GitHub repository for your spellcheck action.

Create a new file in your repository called Dockerfile with the following contents:

This Dockerfile sets up a Node.js environment and installs the cspell package globally.

Create a new file in your repository called entrypoint.sh with the following contents:

This shell script is the entrypoint for the Docker container. It runs the cspell command with any arguments passed to the script, and pipes the output to a file called spellcheck-results.txt. It then runs a Node.js script called index.js.

Create a new file in your repository called index.js with the following contents:

This Node.js script reads the spellcheck-results.txt file and extracts the misspelled words. It then formats the misspelled words as a comment body and posts the comment to the pull request using the GitHub API.

Create a new file in your repository called action.yml with the following contents:

This YAML file defines the GitHub Action. It specifies the name and description of the action, as well as an input for the path to the files to spellcheck. It also specifies that the action should run using Docker, and sets the Docker image to the Dockerfile we created earlier. Finally, it sets the GITHUB_TOKEN environment variable to the value of the secrets.GITHUB_TOKEN secret, which is automatically provided by GitHub.

Commit and push your changes to the repository.

Use the actions/checkout action to check out the repository in your workflow.

Use the actions/setup-node action to set up a Node.js environment in your workflow.

Use the your-username/your-repo-name action to run the spellcheck action in your workflow, passing the path to the files to spellcheck as an input.

Here's an example of how to use the your-username/your-repo-name action in a GitHub Actions workflow:

` name: Spellcheck

on: [pull_request]

jobs:
  spellcheck:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Set up Node.js
        uses: actions/setup-node@v2
        with:
          node-version: '14.x'
      - name: Spellcheck
        uses: your-username/your-repo-name@v1
        with:
          path: '.'
      - name: Post spellcheck results
        uses: actions/github-script@v4
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
        const context = github.context
        const octokit = github.getOctokit(core.getInput('token'))

        const results = fs.readFileSync('spellcheck-results.txt', 'utf8')
        const lines = results.split('\n')
        const misspelledWords = lines.slice(1, -2).map(line => line.trim())

        if (misspelledWords.length === 0) {
          console.log('No misspelled words found.')
          return
        }

        const body = `**Spellcheck Results:**

        ${misspelledWords.join('\n')}`

        await octokit.issues.createComment({
          owner: context.repo.owner,
          repo: context.repo.repo,
          issue_number: context.issue.number,
          body
        })`

In this example, we're using the your-username/your-repo-name action to run the spellcheck action. We're passing the path to the files to spellcheck as an input using the with directive.

We're also using the actions/github-script action to post a summary of the spellcheck results as a comment on the pull request. We're using the fs.readFileSync() method to read the spellcheck-results.txt file, and we're using the split() and map() methods to extract the misspelled words. We're then formatting the misspelled words as a comment body and posting the comment to the pull request using the GitHub API.

Resources:

Justin-Quinn51 commented 11 months ago

Hi @eprice555 & @rcmtcristian. Would you guys be open to me helping with this issue? It would be great to work with another 100Devs alumnus.