Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a tag on GitHub when a PR is merged?

My current workflow requires a version Bump on every PR, so I would like to take advantage of that and automatically create a tag on GitHub on every PR merge, so it appears in the "release" section.

I've seen that I can write a post-merge hook. My doubt is if that hook runs locally in my machine, remotely on GitHub, or both (given that I merge the PR on GitHub, and not locally. What's the case?

like image 240
Tomas Romero Avatar asked Jul 24 '15 04:07

Tomas Romero


People also ask

How do I add tags to GitHub pr?

You can't. A pull request does not include tags. A pull request is only a pointer to a thread of commits (a branch) in your repository that you're proposing another repository to merge.

Do tags get merged Git?

Tags are not merged, commits (tagged or not) are.


1 Answers

I can write a post-merge hook. My doubt is if that hook runs locally in my machine, remotely on GitHub, or both

2015: It will certainly not run on GitHub (that wouldn't be safe for GitHub to run any user-provided hook).

What you can have is a Webhook on pull request: by listening to its JSON payload, you can add a tag and push it back to GitHub if the PR event indicated a merged PR.
(That is, if the action is "closed", and the merged key is "true")


2020: it will certainly run on GitHub: that is called GitHub Actions.

In the OP's case, the GitHub Tag Action.

A GitHub Action to automatically bump and tag master, on merge, with the latest SemVer formatted version. Works on any platform.

Usage

name: Bump version
on:
  push:
    branches:
      - master
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
        with:
          # Fetches entire history, so we can analyze commits since last tag
          fetch-depth: 0
      - name: Bump version and push tag
        uses: mathieudutour/[email protected]
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}

A similar and more up-to-date Action: github-tag-action.
See "Creating A Github Action to Tag Commits" from Nick Sjostrom.

name: Bump version
on:
  push:
    branches:
      - master
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - name: Bump version and push tag
      uses: anothrNick/github-tag-action@master
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        REPO_OWNER: anothrNick
like image 117
VonC Avatar answered Nov 06 '22 20:11

VonC