mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-29 08:35:15 +08:00
Check before publish latest
This commit is contained in:
parent
b1ffbe561e
commit
2c8eb92537
48
.github/scripts/is-latest-release.sh
vendored
Normal file
48
.github/scripts/is-latest-release.sh
vendored
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Used in our CIs to publish the latest Docker image.
|
||||||
|
|
||||||
|
# Checks if the current tag ($GITHUB_REF) corresponds to the latest release tag on GitHub
|
||||||
|
# Returns "true" or "false" (as a string) as a string.
|
||||||
|
|
||||||
|
GITHUB_API='https://api.github.com/repos/meilisearch/meilisearch/releases'
|
||||||
|
PNAME='meilisearch'
|
||||||
|
|
||||||
|
# FUNCTIONS
|
||||||
|
|
||||||
|
# Returns the version of the latest stable version of Meilisearch by setting the $latest variable.
|
||||||
|
get_latest() {
|
||||||
|
# temp_file is needed because the grep would start before the download is over
|
||||||
|
temp_file=$(mktemp -q /tmp/$PNAME.XXXXXXXXX)
|
||||||
|
latest_release="$GITHUB_API/latest"
|
||||||
|
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "$0: Can't create temp file."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$GITHUB_PAT" ]; then
|
||||||
|
curl -s "$latest_release" > "$temp_file" || return 1
|
||||||
|
else
|
||||||
|
curl -H "Authorization: token $GITHUB_PAT" -s "$latest_release" > "$temp_file" || return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
latest="$(cat "$temp_file" | grep '"tag_name":' | cut -d ':' -f2 | tr -d '"' | tr -d ',' | tr -d ' ')"
|
||||||
|
|
||||||
|
rm -f "$temp_file"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# MAIN
|
||||||
|
current_tag="$(echo $GITHUB_REF | tr -d 'refs/tags/')"
|
||||||
|
get_latest
|
||||||
|
|
||||||
|
if [ "$current_tag" != "$latest" ]; then
|
||||||
|
# The current release tag is not the latest
|
||||||
|
echo "false"
|
||||||
|
else
|
||||||
|
# The current release tag is the latest
|
||||||
|
echo "true"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit 0
|
9
.github/workflows/publish-docker-images.yml
vendored
9
.github/workflows/publish-docker-images.yml
vendored
@ -26,15 +26,20 @@ jobs:
|
|||||||
# - a `vX.Y` (without patch version) Docker tag
|
# - a `vX.Y` (without patch version) Docker tag
|
||||||
# - a `latest` Docker tag
|
# - a `latest` Docker tag
|
||||||
# For any other tag pushed, this is not considered stable.
|
# For any other tag pushed, this is not considered stable.
|
||||||
- name: Define if stable release
|
- name: Define if stable and latest release
|
||||||
id: check-tag-format
|
id: check-tag-format
|
||||||
|
env:
|
||||||
|
# To avoid request limit with the .github/scripts/is-latest-release.sh script
|
||||||
|
GITHUB_PATH: ${{ secrets.MEILI_BOT_GH_PAT }}
|
||||||
run: |
|
run: |
|
||||||
escaped_tag=$(printf "%q" ${{ github.ref_name }})
|
escaped_tag=$(printf "%q" ${{ github.ref_name }})
|
||||||
|
echo "latest=false" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
if [[ ${{ github.event_name }} != 'push' ]]; then
|
if [[ ${{ github.event_name }} != 'push' ]]; then
|
||||||
echo "stable=false" >> $GITHUB_OUTPUT
|
echo "stable=false" >> $GITHUB_OUTPUT
|
||||||
elif [[ $escaped_tag =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
elif [[ $escaped_tag =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||||
echo "stable=true" >> $GITHUB_OUTPUT
|
echo "stable=true" >> $GITHUB_OUTPUT
|
||||||
|
echo "latest=$(sh .github/scripts/is-latest-release.sh)" >> $GITHUB_OUTPUT
|
||||||
else
|
else
|
||||||
echo "stable=false" >> $GITHUB_OUTPUT
|
echo "stable=false" >> $GITHUB_OUTPUT
|
||||||
fi
|
fi
|
||||||
@ -76,7 +81,7 @@ jobs:
|
|||||||
type=ref,event=tag
|
type=ref,event=tag
|
||||||
type=raw,value=nightly,enable=${{ github.event_name != 'push' }}
|
type=raw,value=nightly,enable=${{ github.event_name != 'push' }}
|
||||||
type=semver,pattern=v{{major}}.{{minor}},enable=${{ steps.check-tag-format.outputs.stable == 'true' }}
|
type=semver,pattern=v{{major}}.{{minor}},enable=${{ steps.check-tag-format.outputs.stable == 'true' }}
|
||||||
type=raw,value=latest,enable=${{ steps.check-tag-format.outputs.stable == 'true' }}
|
type=raw,value=latest,enable=${{ steps.check-tag-format.outputs.stable == 'true' && steps.check-tag-format.outputs.latest == 'true' }}
|
||||||
|
|
||||||
- name: Build and push
|
- name: Build and push
|
||||||
uses: docker/build-push-action@v3
|
uses: docker/build-push-action@v3
|
||||||
|
Loading…
Reference in New Issue
Block a user