The GitHub Script Action is a very powerful Github Action that can be used in your workflows.
It uses Octokit to help make calling GitHub API's easy and repeatable. With this information, you can then create issues, create releases, update endpoints, etc. Below is a simple example of creating and updating an issue using the tooling.
-
Create a new branch called
Scripts
-
Create a new file named
.github/workflows/create-issue.yml
-
Copy the code below to the newly created file:
# This is a basic workflow to help you get started with Actions name: Create Issue # Controls when the action will run. on: # Triggers the workflow on push or pull request events but only for the main branch push: # Allows you to run this workflow manually from the Actions tab workflow_dispatch: # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: # This workflow contains a single job called "build" build: # The type of runner that the job will run on runs-on: ubuntu-latest # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v2 # Runs a single command using the runners shell - name: Run a one-line script run: echo Hello, world! - name: Create issue uses: actions/[email protected] id: create-issue with: # https://octokit.github.io/rest.js/v18#issues-create github-token: ${{secrets.GITHUB_TOKEN}} script: | const create = await github.issues.create({ owner: context.repo.owner, repo: context.repo.repo, title: "New issue created", body: 'Heres some base data' }) console.log('create', create) return create.data.number - name: Update issue uses: actions/[email protected] with: # https://octokit.github.io/rest.js/v18#issues-create github-token: ${{secrets.GITHUB_TOKEN}} script: | github.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: "${{ steps.create-issue.outputs.result }}", title: "New issue created", body: 'Adding a comment!' })
-
Commit the file.
-
Open a pull request with the
Scripts
branch into themain
branch. -
Merge the pull request.