diff --git a/.github/scripts/is-latest-release.sh b/.github/scripts/is-latest-release.sh new file mode 100644 index 000000000..720dfdf4f --- /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). + +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/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 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/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 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: diff --git a/.github/workflows/publish-docker-images.yml b/.github/workflows/publish-docker-images.yml index 17e85b322..2d95e6784 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,33 @@ 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 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 [[ $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 + echo "latest=$(sh .github/scripts/is-latest-release.sh)" >> $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 +64,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,19 +74,18 @@ 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' }} + 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 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 +94,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 }}