How to cut tagged releases from the default repo branch #42
-
I am a bit unsure if I understand what this does. So I am going to give an example for a workflow and explain what I expect this is doing. If this is correct you could include this example in your readme (I can create a pull request if you want). If this is false please correct me: name: publish
on:
push:
branches:
- master
# the following would create a release on any tag creation not necessarily a tag
# referring to a commit on master (i.e. tagged commits in branches would cause
# releases)
# tags:
# - 'v*'
jobs:
pypi:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: build package
run: python setup.py sdist bdist_wheel
- name: publish to PyPI
# only create relases from tagged commits to master:
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@v1.4.1
with:
user: __token__ # use pypi token instead of username/password
password: ${{ secrets.pypi_token }} # use secret from github secrets and another question: can I somehow restrict tagnames to |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 11 replies
-
apparently I can not read: I am still unsure on how it ensures only tags on master are used. But this cleared a lot of things up |
Beta Was this translation helpful? Give feedback.
-
It appears that I woder if |
Beta Was this translation helpful? Give feedback.
-
A tag is a reference to a specific reference (like a commit), and is not associated with a branch. This SO answer provides a really good summary of how git branches and tags work. |
Beta Was this translation helpful? Give feedback.
-
The name: publish
on:
release:
types:
- "published"
jobs:
pypi:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2.1.2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: build package
run: python setup.py sdist bdist_wheel
- name: publish to PyPI
# only create relases from tagged commits to master:
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@v1.4.1
with:
# if no "user:" specified use pypi token instead of username/password
password: ${{ secrets.pypi_token }} # use secret from github secrets |
Beta Was this translation helpful? Give feedback.
-
The problem statementI take it you want to ensure that the tags causing your dist to be published "belong" to the main branch in your repository. This does sound straightforward high-level but the actual implementation may be rather complicated. And here's why. How stuff worksFirst of all, there are multiple technical sides to this puzzle. Let's explore each one of them. GitIn Git, tags are roughly pointers to commits. Branches are also labels on commits. There is absolutely no direct relationship between these two except that they both can be resolved to commit hashes. So just by knowing a tag name and a branch name, there's zero chance to figure out if that tag "belongs" to a given branch. It is possible to establish, though, if a commit the tag is associated with belongs to a branch. This means that in order to know if a tag is counted as pointing to something on a branch programmatically, we need a copy of the Git repo tree. One more thing, when the true merge commits are used, you'll see forks with subpaths in commit-tree graphs. It may come as a surprise but all of the commits that may seem to be belonging to another branch would also belong to the main branch upon merging. Let's look at this example: E * <- (branch: main)
|
D * <- [merge commit -- it has two parents: C and H]
|\
C * * H
| * G <- (tag: v1.0.0)
B * * F
|/
A * In this graph, commits Some projects use release-PRs: they make all necessary final release preparations in a branch their upstream repositories, then create a PR and tag the head of that branch. Events on the GitHub platformWhenever something happens on GitHub, like actions performed by users or integrations, they are exposed as events that can be analyzed or reacted upon programmatically. There's Events API and webhooks for this — one can either poll GitHub for what's happened or subscribe for events to be delivered to their server by GitHub. Now, let's take a look at what various events mean (amongst those related to our current needs):
GitHub Actions workflow triggersGitHub Actions workflows are built on top of GitHub Apps and the idea of subscribing to certain events that GitHub platform emits, including but not limited to the ones I mentioned above, and then firing up whatever scenarios you have defined. One workflow may subscribe to multiple events allowing to reuse the same collection of jobs and steps. You can also make some jobs and steps conditional and use event names and their context information to filter out things you don't want to run in some cases. Some of the event triggers ( There's many approaches to deciding how to trigger building and publishing automatic releases. Although, I think that the best semantically correct event to use for tag-based triggers would be if: github.event_name != 'create' || github.ref_type == 'tag' The last variant of trigger I want to talk about is Oh, and I want to emphasize that you can combine various triggers in order to create an automation that suits your needs best. Huh?Yeah, this probably sounds complicated but it is what it is. Based on the above, here's a final advice:
|
Beta Was this translation helpful? Give feedback.
The problem statement
I take it you want to ensure that the tags causing your dist to be published "belong" to the main branch in your repository. This does sound straightforward high-level but the actual implementation may be rather complicated. And here's why.
How stuff works
First of all, there are multiple technical sides to this puzzle. Let's explore each one of them.
Git
In Git, tags are roughly pointers to commits. Branches are also labels on commits. There is absolutely no direct relationship between these two except that they both can be resolved to commit hashes.
So just by knowing a tag name and a branch name, there's zero chance to figure out if that tag "belongs" to a given b…