• Stars
    star
    172
  • Rank 221,201 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created about 4 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A GitHub Action to add latest changes after each PR merged automatically

Latest Changes

Automatically add the changes from each PR to the release notes in a file.

How to use

Install this GitHub action by creating a file in your repo at .github/workflows/latest-changes.yml.

A minimal example could be:

name: Latest Changes

on:
  pull_request_target:
    branches:
      - main
      # Or use the branch "master" if that's your main branch:
      # - master
    types:
      - closed
  # For manually triggering it
  workflow_dispatch:
    inputs:
      number:
        description: PR number
        required: true

jobs:
  latest-changes:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: docker://tiangolo/latest-changes:0.0.3
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

Note: you can also use the GitHub action directly intead of with Docker, but that would take an extra minute:

      # - uses: docker://tiangolo/latest-changes:0.0.3
      # This is slower but also works
      - uses: tiangolo/latest-changes:0.0.3

In this minimal example, it uses all the default configurations.

After merging a PR to the main branch, it will:

  • Find a file README.md
  • Inside of that file, find a "header" with the text:
### Latest Changes

...including the two breaking lines.

  • Right after that, it will add a new list item with the changes:
    • Using the title from the PR.
      • Tip: make sure the PR has the title you want before merging it.
    • Including the PR number, with a link to the PR itself.
    • Including the PR author, with a link as well.

It will look something like:

Latest Changes

  • ✨ Add support for Jinja2 templates for latest changes messages. PR #23 by @tiangolo.

You can see an example of how it works in this same file, at the bottom, in Latest Changes - Latest Changes 🀷.

  • Then it will commit the changes, and push them to your repo. πŸš€

As the changes are simply written to a file in your repo, you can later tweak them however you want. You can add links, extend the information, remove irrelevant changes, etc. ✨

Existing PRs - Running Manually

For this GitHub Action to work automatically, the workflow file has to be in the repository before the PR is created, so that the PR also includes it. That's just how GitHub Actions work.

Nevertheless, if you have some PRs that were open before adding this GitHub Action to your project and you still want to use it, you can create workflows manually. It will take the PR number, and then it will do the rest automatically.

You can "dispatch" a workflow/run from the "Actions" tab:

  • Select this GitHub Action with the name you used, e.g. "Latest Changes".
  • Click on "Run Workflow".
  • It will ask you for the PR number and do all the rest.

So, in those cases, it won't do everything automatically, you will have to manually start it and set the PR number. But it can still save you from most of the work, and from a bunch of human errors. πŸ€“ πŸŽ‰

Configuration

You can configure:

  • latest_changes_file: The file to modify with the latest changes. For example: ./docs/latest-changes.rst.
  • latest_changes_header: The header to look for before adding a new message. for example: # CHANGELOG \n\n.
  • template_file: A custom Jinja2 template file to use to generate the message, you could use this to generate a different message or to use a different format, for example, HTML instead of the default Markdown.
  • debug_logs: Set to 'true' to show logs with the current settings.

Configuration example

A full example, using all the configurations, could be as follows.

You could have a custom Jinja2 template with the message to write at ./.github/workflows/release-notes.jinja2 containing:

This changed: {{pr.title}}. Done by [the GitHub user {{pr.user.login}}]({{pr.user.html_url}}). Check the [Pull Request {{pr.number}} with the changes and stuff]({{pr.html_url}}). now back to code. πŸ€“

Note: you can use any location in your repository for the Jinja2 template.

Tip: The pr object is a PyGitHub PullRequest object, you can extract any other information you need from it.

Notice that the Jinja2 template has 2 trailing newlines. Jinja2 we need one so that the next message shows below, instead of the same line, and Jinja2 eats one 🀷, so we put 2.

Then you could have a workflow like:

name: Latest Changes

on:
  pull_request_target:
    branches:
      - master
    types:
      - closed
  workflow_dispatch:
    inputs:
      number:
        description: PR number
        required: true

jobs:
  latest-changes:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: tiangolo/latest-changes:0.0.3
      with:
        token: ${{ secrets.GITHUB_TOKEN }}
        latest_changes_file: docs/release-notes.md
        latest_changes_header: '# Release Notes\n\n'
        template_file: ./.github/workflows/release-notes.jinja2
        debug_logs: true

In this custom config:

  • The main branch is master instead of main.
  • It uses the GitHub action directly:
tiangolo/latest-changes:0.0.3

instead of with Docker:

docker://tiangolo/latest-changes:0.0.3

Note: that would make every run about 1 min slower, but you can do that if you prefer it 🀷.

  • It modifies the file docs/release-notes.md instead of the default README.md.
  • It looks for a header in that file with:
# Release Notes

Note: The latest_changes_header is a regular expression. In this case it has two newlines, and the mesage will be added right after that (without adding an extra newline).

So it will generate messages like:

# Release Notes

* This changed: ✨ Add support for Jinja2 templates for changes notes. Done by [the GitHub user tiangolo](https://github.com/tiangolo). Check the [Pull Request 23 with the changes and stuff](https://github.com/tiangolo/latest-changes/pull/23). now back to code. πŸ€“

And that Markdown will be shown like:

Release Notes

Note: if you use the default of ### Latest Changes\n\n, or add one like the one in this example with two newlines, this GitHub action will expect the two newlines to exist. But if your release notes are empty and the file only contains:

# Release Notes

then this action won't be able to add the first message. So, make sure the latest changes file has the format expected, for example with the two newlines:

# Release Notes

  • Lastly, it will show a lot of debugging information.

Protected Branches

If you have a protected branch (for example main or master), this action wouldn't be able to write and push the updated latest changes to it.

But it's easy to fix if you are an admin in the repo and can push directly to the protected branch.

You need to create a new GitHub access token. For example, a personal access token. You will probably need to give it repo permissions.

Then, in your repository, go to "Settings" -> "Secrets", and create a new "repository secret". Use the access token as the value, and for the name, it could be something like ACTIONS_TOKEN. Just remember to use the same name in the configurations shown below.

Then in your configuration, pass that token to the action actions/checkout@v2:

      - uses: actions/checkout@v2
        with:
          token: ${{ secrets.ACTIONS_TOKEN }}

Note: you pass that token to the official actions/checkout@v2, not to this latest-changes action.

The complete example would look like:

name: Latest Changes

on:
  pull_request_target:
    branches:
      - main
      # Or use the branch "master" if that's your main branch:
      # - master
    types:
      - closed
  # For manually triggering it
  workflow_dispatch:
    inputs:
      number:
        description: PR number
        required: true

jobs:
  latest-changes:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          token: ${{ secrets.ACTIONS_TOKEN }}
      - uses: docker://tiangolo/latest-changes:0.0.3
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

How does it work?

By passing the custom access token to the action actions/checkout@v2, this action will configure git with those credentials.

And then when latest-changes runs and executes some commands with git, including git push, they will be done with your access token.

Your access token will be used to push the changes, but don't worry, the commits will not be associated with your personal user account.

latest-changes still configures the git user with:

So, the commits will still be shown as made by github-actions.

Release Notes

Latest Changes - Latest Changes 🀷

  • πŸ“ Add docs for using latest-changes with protected branches. PR #43 by @tiangolo.

0.0.3

  • 🚚 Update Python module name to latest_changes to avoid conflicts with any repo directory "app". PR #37 by @tiangolo.
  • πŸ› Fix default Jinja2 path in Action yaml. PR #38 by @tiangolo.

0.0.2

  • ✨ Check if the latest changes message was already added before adding it. PR #35 by @tiangolo.
  • πŸ“ Add docs for running manually, with a workflow dispatch. PR #34 by @tiangolo.
  • ✨ Refactor and add support for triggering with workflow dispatch events. PR #32 by @tiangolo.
  • πŸ› Fix basic example in README, include checkout step. PR #31 by @tiangolo.

0.0.1

  • πŸ“ Add note about updating the PR title. PR #30 by @tiangolo.
  • πŸ› Fix internal latest changes, use a custom header so it doesn't break the examples. PR #29 by @tiangolo.
  • πŸ› Fix default action config for template file. PR #28 by @tiangolo.
  • ✨ Add support for Jinja2 templates for changes notes. PR #23 by @tiangolo.
  • πŸ”₯ Remove unnecessary note from release notes. PR #22 by @tiangolo.
  • πŸ”₯ Remove unnecessary note from latest changes. PR #21 by @tiangolo.
  • πŸ”§ Update tmate config keys. PR #20 by @tiangolo.
  • πŸ”’ Update tmate config for keys. PR #19 by @tiangolo.
  • ✏️ Fix incorrect URL. PR #18 by @tiangolo.
  • πŸ”’ Try to secure tmate. PR #17 by @tiangolo.
  • πŸ“ Update release notes URLs. PR #16 by @tiangolo.

License

This project is licensed under the terms of the MIT license.

More Repositories

1

fastapi

FastAPI framework, high performance, easy to learn, fast to code, ready for production
Python
73,897
star
2

full-stack-fastapi-template

Full stack, modern web application template. Using FastAPI, React, SQLModel, PostgreSQL, Docker, GitHub Actions, automatic HTTPS and more.
TypeScript
24,890
star
3

typer

Typer, build great CLIs. Easy to code. Based on Python type hints.
Python
14,943
star
4

sqlmodel

SQL databases in Python, designed for simplicity, compatibility, and robustness.
Python
13,694
star
5

uwsgi-nginx-flask-docker

Docker image with uWSGI and Nginx for Flask applications in Python running in a single container.
Python
2,986
star
6

uvicorn-gunicorn-fastapi-docker

Docker image with Uvicorn managed by Gunicorn for high-performance FastAPI web applications in Python with performance auto-tuning.
Python
2,699
star
7

asyncer

Asyncer, async and await, focused on developer experience.
Python
1,517
star
8

pydantic-sqlalchemy

Tools to convert SQLAlchemy models to Pydantic models
Python
1,173
star
9

nginx-rtmp-docker

Docker image with Nginx using the nginx-rtmp-module module for live multimedia (video) streaming.
Dockerfile
1,110
star
10

dockerswarm.rocks

Docker Swarm mode rocks! Ideas, tools and recipes. Get a production-ready, distributed, HTTPS served, cluster in minutes, not weeks.
Python
1,093
star
11

uwsgi-nginx-docker

Docker image with uWSGI and Nginx for applications in Python (as Flask) in a single container.
Python
646
star
12

uvicorn-gunicorn-docker

Docker image with Uvicorn managed by Gunicorn for high-performance web applications in Python with performance auto-tuning.
Python
628
star
13

full-stack

Full stack, modern web application generator. Using Flask, PostgreSQL DB, Docker, Swagger, automatic HTTPS and more.
Python
523
star
14

meinheld-gunicorn-flask-docker

Docker image with Meinheld and Gunicorn for Flask applications in Python.
Python
486
star
15

full-stack-fastapi-couchbase

Full stack, modern web application generator. Using FastAPI, Couchbase as database, Docker, automatic HTTPS and more.
Python
440
star
16

typer-cli

Run Typer scripts with completion, without having to create a package, using Typer CLI.
Python
367
star
17

poetry-version-plugin

Poetry plugin for dynamically extracting the package version from a __version__ variable or a Git tag.
Python
361
star
18

fastapi-cli

Run and manage FastAPI apps from the command line with FastAPI CLI. πŸš€
Python
287
star
19

blog-posts

Blog posts and related code by SebastiΓ‘n RamΓ­rez (@tiangolo)
Python
273
star
20

uvicorn-gunicorn-starlette-docker

Docker image with Uvicorn managed by Gunicorn for high-performance Starlette web applications in Python with performance auto-tuning.
Python
182
star
21

babun-docker

Use Docker Toolbox with Babun (Cygwin) in Windows
Shell
170
star
22

meinheld-gunicorn-docker

Docker image with Meinheld managed by Gunicorn for high-performance WSGI (Flask, Django, etc) web applications in Python with performance auto-tuning.
Python
165
star
23

docker-with-compose

Docker image with Docker Compose installed for CI.
Shell
158
star
24

node-frontend

Instrutctions to buid a frontend Docker image built with Node.js and then served with Nginx. Previously a Docker image.
Dockerfile
137
star
25

flask-frontend-docker

Minimal project generator with a Flask backend, a modern frontend (Vue, React or Angular), a Traefik load balancer with HTTPS, all based on Docker.
Vue
130
star
26

python-machine-learning-docker

Docker image with Python 3.6 and 3.7 using Conda, with CUDA variants. To serve as base image for Machine Learning projects.
Dockerfile
84
star
27

uvicorn-gunicorn-machine-learning-docker

Docker image for high-performance Machine Learning web applications. With Uvicorn managed by Gunicorn in Python 3.7 and 3.6, using Conda, with CUDA and TensorFlow variants.
Python
67
star
28

issue-manager

Automatically close issues that have a label, after a custom delay, if no one replies back.
Python
62
star
29

full-stack-flask-couchbase

Full stack, modern web application generator. Using Flask, Couchbase as database, Docker, Swagger, automatic HTTPS and more.
Python
59
star
30

label-approved

Label a Pull Request after a number of approvals
Python
34
star
31

full-stack-flask-couchdb

Full stack, modern web application generator. Using Flask, CouchDB as database, Docker, Swagger, automatic HTTPS and more.
Python
31
star
32

tiangolo

16
star
33

github-actions-sandbox

Not useful for you. It's just a sandbox GitHub repo for me to try out stuff and develop GitHub Actions.
Python
16
star
34

tiangolo.com

Python
16
star
35

docker-auto-labels

Generate each Docker constraint label in random nodes in the cluster.
Python
15
star
36

angular-docker-multi-stage-example

Angular in Docker with Nginx, supporting environments, built with multi-stage Docker builds
15
star
37

ngx-http-client

Angular (4.3+) HttpClientModule with parameter encodings compatible with back ends (Node.js, Python, PHP, etc)
TypeScript
11
star
38

compose-to-rancher

Convert Docker Compose V2 to Rancher compatible Docker Compose V1
Python
10
star
39

markdown-include-variants

Markdown extension to expand directives to include source example files to also include their variants. Only useful to tiangolo's projets. Don't use it. πŸ˜…
Python
9
star
40

wunderlist2csv

Convert from Wunderlist backup json file to a CSV file importable by TaskCoach
Python
6
star
41

anaconda_cluster_install

Automatically Install Anaconda Python in a cluster of machines, for a specified user.
Shell
5
star
42

bitbucket_issues_to_redmine_csv

Python
3
star