GitHub Actions let you automate tasks within your repository. While many developers use them for continuous integration or deployment, they can be used to automate all kinds of tasks and supercharge your repository.
In this tutorial, we’ll set up a simple automation that posts a comment whenever someone opens a new issue. It’s an ideal starting point for learning GitHub Actions, and it can help guide users, reinforce contribution standards, or just save you time by automating away repetitive or monotonous tasks.
What We’re Building
This action will listen for new issues being opened in your repository. When that happens, it will run a short JavaScript script that posts a predefined comment in response.
There’s no need to install dependencies or build tools. The entire workflow is handled by GitHub’s infrastructure, using just one workflow file and one script block.
GitHub actions can be a lot of work to fun work with, so let’s get started.
The Workflow File
To create the automation, create a .github
folder, and another workflow
folder within it.
Then, in your new workflows
folder, create a file called auto-comment.yml
(the path should now be .github/workflows/auto-comment.yml
) and include the following:
name: Auto Comment on Issues
on:
issues:
types: [opened]
jobs:
comment:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Comment on new issue
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issueNumber = context.issue.number;
const username = context.payload.issue.user.login;
const comment = [
`👋 Hey @${username} — thanks for opening an issue!`,
``,
`Before we dive in, make sure to check out our [contributing guide](CONTRIBUTING.md) and see if this has already been reported.`,
``,
`We appreciate your help! 💖`
].join('\n');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: comment
});
Walking through the script, here’s how it works:
Setup
- Name: The workflow is called “Auto Comment on Issues”.
- Trigger: It runs automatically when a new issue is opened.
- Environment: Executes on the latest Ubuntu runner provided by GitHub.
- Permissions: Grants permission to write comments on issues.
Main Job:
- Uses the built-in actions/github-script to run JavaScript directly in the workflow.
- Retrieves the issue number and the username of the person who opened it (dynamically).
- Constructs a custom thank-you comment including a link to the contributing guide.
- Posts the comment to the issue using the built-in GitHub REST API.
Formatting
At this point, it’s worth saying that GitHub actions can be quite fussy when it comes to formatting, and if you see one when you first add your workflow file, it’s likely an issue with identations, so start there.
Testing Your Action
Now we’ll make sure your action is working correctly by creating a test issue (don’t worry, we can delete it later).
Then, head to the ‘Actions’ tab on the GitHub repository page and you’ll see logs for each time your workflow runs, making it easier to debug any issues that could popup.
Finally, head back to the Issues tab and you should see a nicely formatted comment waiting for you! Success! 🎊
Summary
So now you know how to setup a GitHub action to automate parts of your developer workflow! If you wanted to take this tutorial a step further, we recommend experimenting with features like:
- Auto-labelling PRs based on file paths
- Close stale PRs after X days of inactivity
- Check for secrets like API keys in commits
We’d love to see what you make, so be sure to share it with us on Bluesky!