Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spellcheck Action #626

Open
2 tasks
eprice555 opened this issue Oct 24, 2023 · 1 comment
Open
2 tasks

Spellcheck Action #626

eprice555 opened this issue Oct 24, 2023 · 1 comment
Assignees
Labels
🏗 architecture ✍️ documentation Improvements or additions to documentation good first issue Good for newcomers oss workflows

Comments

@eprice555
Copy link
Collaborator

eprice555 commented Oct 24, 2023

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
Copy link
Collaborator

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

@Justin-Quinn51 Justin-Quinn51 self-assigned this Oct 25, 2023
@Satoshi-Sh Satoshi-Sh self-assigned this Oct 25, 2023
@christan87 christan87 self-assigned this Nov 3, 2023
@Justin-Quinn51 Justin-Quinn51 removed their assignment Nov 15, 2023
@manishapriya94 manishapriya94 changed the title [Architecture] Spellcheck Action [Workflow] Spellcheck Action Dec 8, 2023
@manishapriya94 manishapriya94 changed the title [Workflow] Spellcheck Action Spellcheck Action Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏗 architecture ✍️ documentation Improvements or additions to documentation good first issue Good for newcomers oss workflows
Projects
Status: No status
Status: No status
Development

No branches or pull requests

7 participants