From 3246df89d6d80fc09357b445630fad87f08f57ce Mon Sep 17 00:00:00 2001
From: Matthew Armand <marmand68@gmail.com>
Date: Tue, 20 Dec 2022 22:18:15 -0500
Subject: [PATCH] Add latest_prerelease Docker Hub tag for following the latest
 alpha release (#3465)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
---
 .github/workflows/docker.yml                       | 11 +++++++++++
 CHANGES.md                                         |  2 ++
 docs/usage_and_configuration/black_docker_image.md |  5 +++++
 3 files changed, 18 insertions(+)

diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml
index 855186f..04e30e7 100644
--- a/.github/workflows/docker.yml
+++ b/.github/workflows/docker.yml
@@ -54,5 +54,16 @@ jobs:
           push: true
           tags: pyfound/black:latest_release
 
+      - name: Build and push latest_prerelease tag
+        if:
+          ${{ github.event_name == 'release' && github.event.action == 'published' &&
+          github.event.release.prerelease }}
+        uses: docker/build-push-action@v3
+        with:
+          context: .
+          platforms: linux/amd64,linux/arm64
+          push: true
+          tags: pyfound/black:latest_prerelease
+
       - name: Image digest
         run: echo ${{ steps.docker_build.outputs.digest }}
diff --git a/CHANGES.md b/CHANGES.md
index c07d81d..c89b106 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -71,6 +71,8 @@
 <!-- For example, Docker, GitHub Actions, pre-commit, editors -->
 
 - Move 3.11 CI to normal flow now all dependencies support 3.11 (#3446)
+- Docker: Add new `latest_prerelease` tag automation to follow latest black alpha
+  release on docker images (#3465)
 
 ### Documentation
 
diff --git a/docs/usage_and_configuration/black_docker_image.md b/docs/usage_and_configuration/black_docker_image.md
index 8de566e..85aec91 100644
--- a/docs/usage_and_configuration/black_docker_image.md
+++ b/docs/usage_and_configuration/black_docker_image.md
@@ -10,6 +10,11 @@ _Black_ images with the following tags are available:
 - `latest_release` - tag created when a new version of _Black_ is released.\
   ℹ Recommended for users who want to use released versions of _Black_. It maps to [the latest release](https://github.com/psf/black/releases/latest)
   of _Black_.
+- `latest_prerelease` - tag created when a new alpha (prerelease) version of _Black_ is
+  released.\
+  ℹ Recommended for users who want to preview or test alpha versions of _Black_. Note that
+  the most recent release may be newer than any prerelease, because no prereleases are created
+  before most releases.
 - `latest` - tag used for the newest image of _Black_.\
   ℹ Recommended for users who always want to use the latest version of _Black_, even before
   it is released.
-- 
2.39.5