2023-03-07 21:55:09 +08:00
name : Publish images to Docker Hub
2019-11-21 18:18:54 +08:00
on :
push :
2022-12-01 19:48:01 +08:00
# Will run for every tag pushed except `latest`
# When the `latest` git tag is created with this [CI](../latest-git-tag.yml)
# we don't need to create a Docker `latest` image again.
# The `latest` Docker image push is already done in this CI when releasing a stable version of Meilisearch.
tags-ignore :
- latest
2022-12-10 03:02:01 +08:00
# Both `schedule` and `workflow_dispatch` build the nightly tag
schedule :
- cron : '0 23 * * *' # Every day at 11:00pm
workflow_dispatch :
2019-11-21 18:18:54 +08:00
jobs :
2022-06-08 23:17:20 +08:00
docker :
2021-12-22 01:32:29 +08:00
runs-on : docker
2019-11-21 18:18:54 +08:00
steps :
2022-09-02 22:45:32 +08:00
- uses : actions/checkout@v3
2022-06-17 01:27:27 +08:00
2022-12-10 03:02:01 +08:00
# If we are running a cron or manual job ('schedule' or 'workflow_dispatch' event), it means we are publishing the `nightly` tag, so not considered stable.
# If we have pushed a tag, and the tag has the v<nmumber>.<number>.<number> format, it means we are publishing an official release, so considered stable.
2022-06-17 01:27:27 +08:00
# In this situation, we need to set `output.stable` to create/update the following tags (additionally to the `vX.Y.Z` Docker tag):
# - a `vX.Y` (without patch version) Docker tag
# - a `latest` Docker tag
2022-12-10 03:02:01 +08:00
# For any other tag pushed, this is not considered stable.
2022-12-12 04:24:52 +08:00
- name : Define if stable and latest release
2022-06-17 01:27:27 +08:00
id : check-tag-format
2022-12-12 04:24:52 +08:00
env :
# To avoid request limit with the .github/scripts/is-latest-release.sh script
GITHUB_PATH : ${{ secrets.MEILI_BOT_GH_PAT }}
2022-06-17 01:27:27 +08:00
run : |
escaped_tag=$(printf "%q" ${{ github.ref_name }})
2022-12-12 04:24:52 +08:00
echo "latest=false" >> $GITHUB_OUTPUT
2022-06-17 01:27:27 +08:00
2022-12-10 03:02:01 +08:00
if [[ ${{ github.event_name }} != 'push' ]]; then
echo "stable=false" >> $GITHUB_OUTPUT
elif [[ $escaped_tag =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
2022-11-10 17:40:16 +08:00
echo "stable=true" >> $GITHUB_OUTPUT
2022-12-12 04:24:52 +08:00
echo "latest=$(sh .github/scripts/is-latest-release.sh)" >> $GITHUB_OUTPUT
2022-06-17 01:27:27 +08:00
else
2022-11-10 17:40:21 +08:00
echo "stable=false" >> $GITHUB_OUTPUT
2022-06-17 01:27:27 +08:00
fi
2022-12-10 03:02:01 +08:00
# Check only the validity of the tag for stable releases (not for pre-releases or other tags)
2022-06-17 01:27:27 +08:00
- name : Check release validity
2022-12-10 03:02:01 +08:00
if : steps.check-tag-format.outputs.stable == 'true'
2022-06-24 01:14:39 +08:00
run : bash .github/scripts/check-release.sh
2022-06-17 01:27:27 +08:00
2022-12-07 04:44:31 +08:00
- name : Set build-args for Docker buildx
id : build-metadata
run : |
# Extract commit date
commit_date=$(git show -s --format=%cd --date=iso-strict ${{ github.sha }})
echo "date=$commit_date" >> $GITHUB_OUTPUT
2021-11-11 22:57:06 +08:00
- name : Set up QEMU
2022-06-29 04:21:38 +08:00
uses : docker/setup-qemu-action@v2
2021-11-11 22:57:06 +08:00
- name : Set up Docker Buildx
2022-06-29 04:21:43 +08:00
uses : docker/setup-buildx-action@v2
2021-11-11 22:57:06 +08:00
2022-06-17 01:27:27 +08:00
- name : Login to Docker Hub
2022-07-02 01:06:38 +08:00
uses : docker/login-action@v2
2021-11-12 02:42:30 +08:00
with :
2022-06-20 20:39:50 +08:00
username : ${{ secrets.DOCKERHUB_USERNAME }}
password : ${{ secrets.DOCKERHUB_TOKEN }}
2021-11-12 02:42:30 +08:00
2021-11-11 22:57:06 +08:00
- name : Docker meta
id : meta
2022-06-29 04:21:32 +08:00
uses : docker/metadata-action@v4
2021-11-11 22:57:06 +08:00
with :
2021-11-12 02:42:30 +08:00
images : getmeili/meilisearch
2022-12-10 03:02:01 +08:00
# Prevent `latest` to be updated for each new tag pushed.
# We need latest and `vX.Y` tags to only be pushed for the stable Meilisearch releases.
2021-11-11 22:57:06 +08:00
flavor : latest=false
2022-06-08 23:17:20 +08:00
tags : |
type=ref,event=tag
2022-12-10 03:02:01 +08:00
type=raw,value=nightly,enable=${{ github.event_name != 'push' }}
2022-06-24 01:14:39 +08:00
type=semver,pattern=v{{major}}.{{minor}},enable=${{ steps.check-tag-format.outputs.stable == 'true' }}
2022-12-12 04:24:52 +08:00
type=raw,value=latest,enable=${{ steps.check-tag-format.outputs.stable == 'true' && steps.check-tag-format.outputs.latest == 'true' }}
2021-11-11 22:57:06 +08:00
- name : Build and push
2023-02-02 01:02:17 +08:00
uses : docker/build-push-action@v4
2019-11-21 18:18:54 +08:00
with :
2022-12-14 21:05:25 +08:00
push : true
2021-11-11 23:28:30 +08:00
platforms : linux/amd64,linux/arm64
2021-11-11 22:57:06 +08:00
tags : ${{ steps.meta.outputs.tags }}
2022-12-07 04:44:31 +08:00
build-args : |
COMMIT_SHA=${{ github.sha }}
COMMIT_DATE=${{ steps.build-metadata.outputs.date }}
2023-02-14 20:50:34 +08:00
GIT_TAG=${{ github.ref_name }}
2022-09-21 17:03:01 +08:00
# /!\ Don't touch this without checking with Cloud team
- name : Send CI information to Cloud team
2022-12-10 03:02:01 +08:00
# Do not send if nightly build (i.e. 'schedule' or 'workflow_dispatch' event)
if : github.event_name == 'push'
2022-09-21 17:03:01 +08:00
uses : peter-evans/repository-dispatch@v2
with :
token : ${{ secrets.MEILI_BOT_GH_PAT }}
repository : meilisearch/meilisearch-cloud
event-type : cloud-docker-build
2022-10-12 15:36:01 +08:00
client-payload : '{ "meilisearch_version": "${{ github.ref_name }}", "stable": "${{ steps.check-tag-format.outputs.stable }}" }'