First we need Personal Access Token (PAT) with workflow permission.
My existing PAT didn't have the permisson to create/update workflows.
So I created a new PAT.
Step 1: Go to your GitHub account settings.
Step 2: Navigate to Developer settings
Step 3: Personal access tokens
Step 4: Generate new token.
Step 5: Select the repo scope including workflow
Copy the PAT and save it securely.
Now open a terminal and check the credential helper.
$ git config --global credential.helper
If it is stores
then edit the ~/.git-credentials
file and add the new PAT.
You should then be able to push the changes with the workflow file.
One last thing, you will need to do is, add the PAT to Repository Secrets:
Step 1: Go to your repository settings.
Step 2: Navigate to Secrets and variables
Step 3: Actions.
Click New repository secret.
Then name the secret WORKFLOW_PAT
and paste the new PAT.
Finally push a new tag, it should create a new release.
The workflow file looks like below:
name: Release on Tag
on:
push:
tags:
- 'v*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
release:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.WORKFLOW_PAT }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false