Prompt Detail:
Sure, to create a GitHub Action that tags a new version in the master branch when a pull request titled with "Release" is merged, you'll need to write a workflow file. Here's a basic outline:
- Trigger: The action should be triggered on pull request events, specifically the
closed
event. - Condition: Check if the pull request is merged and its title starts with "Release".
- Action: Create a new tag and push it to the repository.
Here's a sample .yml
file for your GitHub Action:
yamlname: Tag Release
on:
pull_request:
types: [closed]
branches:
- master
jobs:
tag:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.title, 'Release')
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Git
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
- name: Create Tag
run: |
PR_TITLE="${{ github.event.pull_request.title }}"
VERSION=${PR_TITLE#"Release "}
git tag $VERSION
git push origin $VERSION
This workflow does the following:
- Activates when a pull request to the master branch is closed.
- Checks if the pull request is merged and if its title starts with "Release".
- Configures Git with a default user and email.
- Extracts the version number from the pull request title (assuming the title is like "Release v1.0.0") and creates a tag.
- Pushes the tag to the repository.
Make sure to adapt the script to suit your version naming convention and repository structure. Also, consider adding error handling or additional logging as needed for your use case.