From 84204b8cd574b16072d0b10219de6f1dceaac8e0 Mon Sep 17 00:00:00 2001 From: curquiza Date: Fri, 9 Dec 2022 19:27:58 +0100 Subject: [PATCH 1/6] Replace the released type by published --- .github/workflows/latest-git-tag.yml | 2 +- .github/workflows/publish-deb-brew-pkg.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/latest-git-tag.yml b/.github/workflows/latest-git-tag.yml index e8cbc50f3..0adf0a1c6 100644 --- a/.github/workflows/latest-git-tag.yml +++ b/.github/workflows/latest-git-tag.yml @@ -3,7 +3,7 @@ name: Update latest git tag on: workflow_dispatch: release: - types: [released] + types: [published] jobs: check-version: diff --git a/.github/workflows/publish-deb-brew-pkg.yml b/.github/workflows/publish-deb-brew-pkg.yml index 1f84b84c5..3d9446321 100644 --- a/.github/workflows/publish-deb-brew-pkg.yml +++ b/.github/workflows/publish-deb-brew-pkg.yml @@ -2,7 +2,7 @@ name: Publish to APT repository & Homebrew on: release: - types: [released] + types: [published] jobs: check-version: From b1ffbe561eed808fa246cc1a8c16304518fd9050 Mon Sep 17 00:00:00 2001 From: curquiza Date: Fri, 9 Dec 2022 20:02:01 +0100 Subject: [PATCH 2/6] Add nightly for docker CI --- .github/workflows/publish-docker-images.yml | 31 ++++++++++++--------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/.github/workflows/publish-docker-images.yml b/.github/workflows/publish-docker-images.yml index 17e85b322..a21db7b32 100644 --- a/.github/workflows/publish-docker-images.yml +++ b/.github/workflows/publish-docker-images.yml @@ -1,7 +1,5 @@ --- on: - schedule: - - cron: '0 4 * * *' # Every day at 4:00am push: # Will run for every tag pushed except `latest` # When the `latest` git tag is created with this [CI](../latest-git-tag.yml) @@ -9,6 +7,10 @@ on: # The `latest` Docker image push is already done in this CI when releasing a stable version of Meilisearch. tags-ignore: - latest + # Both `schedule` and `workflow_dispatch` build the nightly tag + schedule: + - cron: '0 23 * * *' # Every day at 11:00pm + workflow_dispatch: name: Publish tagged images to Docker Hub @@ -18,25 +20,28 @@ jobs: steps: - uses: actions/checkout@v3 - # Check if the tag has the v.. format. If yes, it means we are publishing an official release. + # 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.. format, it means we are publishing an official release, so considered stable. # 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 - - name: Check tag format - if: github.event_name != 'schedule' + # For any other tag pushed, this is not considered stable. + - name: Define if stable release id: check-tag-format run: | escaped_tag=$(printf "%q" ${{ github.ref_name }}) - if [[ $escaped_tag =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + if [[ ${{ github.event_name }} != 'push' ]]; then + echo "stable=false" >> $GITHUB_OUTPUT + elif [[ $escaped_tag =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then echo "stable=true" >> $GITHUB_OUTPUT else echo "stable=false" >> $GITHUB_OUTPUT fi - # Check only the validity of the tag for official releases (not for pre-releases or other tags) + # Check only the validity of the tag for stable releases (not for pre-releases or other tags) - name: Check release validity - if: github.event_name != 'schedule' && steps.check-tag-format.outputs.stable == 'true' + if: steps.check-tag-format.outputs.stable == 'true' run: bash .github/scripts/check-release.sh - name: Set build-args for Docker buildx @@ -54,7 +59,6 @@ jobs: uses: docker/setup-buildx-action@v2 - name: Login to Docker Hub - if: github.event_name != 'schedule' uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} @@ -65,11 +69,12 @@ jobs: uses: docker/metadata-action@v4 with: images: getmeili/meilisearch - # The latest and `vX.Y` tags are only pushed for the official Meilisearch releases - # See https://github.com/docker/metadata-action#latest-tag + # 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. flavor: latest=false tags: | type=ref,event=tag + type=raw,value=nightly,enable=${{ github.event_name != 'push' }} 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' }} @@ -77,7 +82,6 @@ jobs: uses: docker/build-push-action@v3 with: # We do not push tags for the cron jobs, this is only for test purposes - push: ${{ github.event_name != 'schedule' }} platforms: linux/amd64,linux/arm64 tags: ${{ steps.meta.outputs.tags }} build-args: | @@ -86,7 +90,8 @@ jobs: # /!\ Don't touch this without checking with Cloud team - name: Send CI information to Cloud team - if: github.event_name != 'schedule' + # Do not send if nightly build (i.e. 'schedule' or 'workflow_dispatch' event) + if: github.event_name == 'push' uses: peter-evans/repository-dispatch@v2 with: token: ${{ secrets.MEILI_BOT_GH_PAT }} From 2c8eb92537929b688ba644d54731e18bed3a1728 Mon Sep 17 00:00:00 2001 From: curquiza Date: Sun, 11 Dec 2022 21:24:52 +0100 Subject: [PATCH 3/6] Check before publish latest --- .github/scripts/is-latest-release.sh | 48 +++++++++++++++++++++ .github/workflows/publish-docker-images.yml | 9 +++- 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 .github/scripts/is-latest-release.sh diff --git a/.github/scripts/is-latest-release.sh b/.github/scripts/is-latest-release.sh new file mode 100644 index 000000000..e61a153e4 --- /dev/null +++ b/.github/scripts/is-latest-release.sh @@ -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 diff --git a/.github/workflows/publish-docker-images.yml b/.github/workflows/publish-docker-images.yml index a21db7b32..89b61fd4d 100644 --- a/.github/workflows/publish-docker-images.yml +++ b/.github/workflows/publish-docker-images.yml @@ -26,15 +26,20 @@ jobs: # - a `vX.Y` (without patch version) Docker tag # - a `latest` Docker tag # 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 + env: + # To avoid request limit with the .github/scripts/is-latest-release.sh script + GITHUB_PATH: ${{ secrets.MEILI_BOT_GH_PAT }} run: | escaped_tag=$(printf "%q" ${{ github.ref_name }}) + echo "latest=false" >> $GITHUB_OUTPUT if [[ ${{ github.event_name }} != 'push' ]]; then echo "stable=false" >> $GITHUB_OUTPUT elif [[ $escaped_tag =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then echo "stable=true" >> $GITHUB_OUTPUT + echo "latest=$(sh .github/scripts/is-latest-release.sh)" >> $GITHUB_OUTPUT else echo "stable=false" >> $GITHUB_OUTPUT fi @@ -76,7 +81,7 @@ jobs: type=ref,event=tag type=raw,value=nightly,enable=${{ github.event_name != 'push' }} 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 uses: docker/build-push-action@v3 From 9a3f9577b880ee3a5b3a58fca578e262fb22270f Mon Sep 17 00:00:00 2001 From: curquiza Date: Sun, 11 Dec 2022 21:26:05 +0100 Subject: [PATCH 4/6] Remove useless line in CI --- .github/workflows/milestone-workflow.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/milestone-workflow.yml b/.github/workflows/milestone-workflow.yml index 3a49b342b..1bf3e3d50 100644 --- a/.github/workflows/milestone-workflow.yml +++ b/.github/workflows/milestone-workflow.yml @@ -31,8 +31,6 @@ jobs: runs-on: ubuntu-latest outputs: is-patch: ${{ steps.check-patch.outputs.is-patch }} - env: - MILESTONE_VERSION: ${{ github.event.milestone.title }} steps: - uses: actions/checkout@v3 - name: Check if this release is a patch release only From 796e61ec7e23bf57c7d805e3d26cbb80a2bf55b8 Mon Sep 17 00:00:00 2001 From: curquiza Date: Sun, 11 Dec 2022 21:29:23 +0100 Subject: [PATCH 5/6] Remove useless CI --- .github/workflows/coverage.yml | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 .github/workflows/coverage.yml diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml deleted file mode 100644 index 54d3b38b4..000000000 --- a/.github/workflows/coverage.yml +++ /dev/null @@ -1,33 +0,0 @@ ---- -on: - workflow_dispatch: - -name: Execute code coverage - -jobs: - nightly-coverage: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly - override: true - - uses: actions-rs/cargo@v1 - with: - command: clean - - uses: actions-rs/cargo@v1 - with: - command: test - args: --all-features --no-fail-fast - env: - CARGO_INCREMENTAL: "0" - RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=unwind -Zpanic_abort_tests" - - uses: actions-rs/grcov@v0.1 - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 - with: - token: ${{ secrets.CODECOV_TOKEN }} - file: ${{ steps.coverage.outputs.report }} - yml: ./codecov.yml - fail_ci_if_error: true From 14824cee864df3b140891484962b605053d6bd2a Mon Sep 17 00:00:00 2001 From: curquiza Date: Sun, 11 Dec 2022 21:44:17 +0100 Subject: [PATCH 6/6] Remove obsolete comment line --- .github/scripts/is-latest-release.sh | 2 +- .github/workflows/publish-docker-images.yml | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/scripts/is-latest-release.sh b/.github/scripts/is-latest-release.sh index e61a153e4..720dfdf4f 100644 --- a/.github/scripts/is-latest-release.sh +++ b/.github/scripts/is-latest-release.sh @@ -3,7 +3,7 @@ # 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. +# Returns "true" or "false" (as a string). GITHUB_API='https://api.github.com/repos/meilisearch/meilisearch/releases' PNAME='meilisearch' diff --git a/.github/workflows/publish-docker-images.yml b/.github/workflows/publish-docker-images.yml index 89b61fd4d..2d95e6784 100644 --- a/.github/workflows/publish-docker-images.yml +++ b/.github/workflows/publish-docker-images.yml @@ -86,7 +86,6 @@ jobs: - name: Build and push uses: docker/build-push-action@v3 with: - # We do not push tags for the cron jobs, this is only for test purposes platforms: linux/amd64,linux/arm64 tags: ${{ steps.meta.outputs.tags }} build-args: |