diff --git a/.cirrus.yml b/.cirrus.yml index 4fc2ae051..716ba6d14 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -1,71 +1,20 @@ freebsd_instance: - image: freebsd-12-2-release-amd64 + image_family: freebsd-13-0 build_task: - env: - GITHUB_TOKEN: ENCRYPTED[!1ecc3020fe8c6463c06ebc22153533239e132ee56e4faad95ce336bd2ee2bde6aa89c0352e89faaa2c10f4a5bac9b7fc!] - # caches the freebsd package downloads - # saves probably just a couple of seconds, but hey... - pkg_cache: - folder: /var/cache/pkg + name: Build FreeBSD (Stack) + install_script: pkg install -y postgresql13-client hs-stack - install_script: - # - pkg update - - pkg install -y postgresql12-client ghc hs-cabal-install jq git - - # cache the hackage index file and downloads which are - # cabal v2-update downloads an incremental update, so we don't need to keep this up2date - packages_cache: - # warning: don't use ~/.cabal here, this will break the cache - folder: /.cabal/packages + stack_cache: + folders: /.stack + fingerprint_script: cat stack.yaml.lock reupload_on_changes: false - # cache the dependencies built by cabal - # they have to be uploaded on every change to make the next build fast - store_cache: - # warning: don't use ~/.cabal here, this will break the cache - folder: /.cabal/store - fingerprint_script: cat postgrest.cabal - reupload_on_changes: true + stack_work_cache: + folders: .stack-work + fingerprint_script: cat stack.yaml.lock + reupload_on_changes: false - build_script: - - cabal v2-update - - | - if test "$CIRRUS_TAG" = "nightly" - then - cabal_nightly_version=$(git show -s --format='%cd' --date='format:%Y%m%d') - sed -i '' "s/^version:.*/version:$cabal_nightly_version/" postgrest.cabal - fi - ## compile for 30 minutes tops - - timeout 1800 cabal v2-build -j1 || test "$?" = "124" - - publish_script: - - | - if test ! "$CIRRUS_TAG" - then - echo 'No tag pushed. Skip release.' - else - cabal v2-install - - bin_name="" - - if test $CIRRUS_TAG = "nightly" - then - suffix=$(git show -s --format="%cd-%h" --date="format:%Y-%m-%d-%H-%M") - bin_name=postgrest-nightly-$suffix-freebsd.tar.xz - else - bin_name=postgrest-$CIRRUS_TAG-freebsd.tar.xz - fi - - release_id=$(curl -s https://api.github.com/repos/$CIRRUS_REPO_FULL_NAME/releases/tags/$CIRRUS_TAG | jq .id) - - echo "Uploading $bin_name to gh release: $release_id" - - tar cvJf $bin_name --dereference -C /.cabal/bin postgrest - - ## We don't use ghr here because it doesn't provide freebsd binaries: https://github.com/tcnksm/ghr/issues/127 - curl -X POST --data-binary @$bin_name \ - -H "Authorization:token $GITHUB_TOKEN" \ - -H "Content-Type:application/octet-stream" \ - "https://uploads.github.com/repos/$CIRRUS_REPO_FULL_NAME/releases/$release_id/assets?name=$bin_name" - fi + build_script: stack build -j 1 --local-bin-path . --copy-bins + bin_artifacts: + path: postgrest diff --git a/.github/get_cirrusci_freebsd b/.github/get_cirrusci_freebsd new file mode 100755 index 000000000..5da40ed03 --- /dev/null +++ b/.github/get_cirrusci_freebsd @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Get the FreeBSD PostgREST executable built by CirrusCI for the given GITHUB_COMMIT in GITHUB_REPOSITORY + +# We use the GitHub API for 'check suites' to find the corresponding CirrusCI job, see: +# https://docs.github.com/en/rest/reference/checks#list-check-suites-for-a-git-reference + +cirrus_artifact_name=bin +gh_accept_header="Accept: application/vnd.github.v3+json" + +get_gh_check_runs_url() { + gh_checks_list_url="https://api.github.com/repos/$GITHUB_REPOSITORY/commits/$GITHUB_COMMIT/check-suites" + >&2 echo "Getting list of check-suites from $gh_checks_list_url ..." + curl --fail -H "$gh_accept_header" "$gh_checks_list_url" \ + | jq -r '.check_suites[] | select(.app.slug == "cirrus-ci") | .check_runs_url' +} + +wait_for_cirrusci() { + gh_check_runs_url="$(get_gh_check_runs_url)" + >&2 echo "Waiting to CirrusCI run to complete (two hours maximum)..." + for _ in $(seq 1 120); do + echo "Checking for CirrusCI task status at $gh_check_runs_url ..." + status=$(curl --fail "$gh_check_runs_url" | jq -r '.check_runs[] | .status') + if [ "$status" == "completed" ]; then + break + else + echo "CirrusCI task is still $status, waiting..." + sleep 60 + fi + done +} + +# The CirrusCI taskid can change if a new check run is started for the same commit, +# e.g. when pushing both a branch and tag. We make sure that we have the very +# latest taskid by re-loading the 'gh_check_runs_url' and the 'check run' itself. +get_cirrus_taskid() { + gh_check_runs_url="$(get_gh_check_runs_url)" + >&2 echo "Getting the CirrusCI task id from $gh_check_runs_url ..." + curl --fail -H "$gh_accept_header" "$gh_check_runs_url" \ + | jq -r '.check_runs[] | .external_id' +} + +download_artifact() { + cirrus_task_id="$(get_cirrus_taskid)" + cirrus_artifact_url="https://api.cirrus-ci.com/v1/artifact/task/$cirrus_task_id/$cirrus_artifact_name.zip" + >&2 echo "Attemping to download the CirrusCI artifact from $cirrus_artifact_url ..." + curl --fail "$cirrus_artifact_url" -o freebsd.zip +} + +wait_for_cirrusci +download_artifact + +echo "Unpacking executable..." +unzip freebsd.zip -d . +rm -rf freebsd.zip diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 000000000..668705f04 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,358 @@ +name: CI +on: + - push + - pull_request + +jobs: + Lint-Style: + name: Lint & check code style + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: cachix/install-nix-action@v13 + - name: Install linting and styling scripts + run: nix-env -f default.nix -iA style + - name: Run linter (check locally with `nix-shell --run postgrest-lint`) + run: postgrest-lint + - name: Run style check (auto-format with `nix-shell --run postgrest-style`) + run: postgrest-style-check + + Test-Nix: + name: Test (Nix) + runs-on: ubuntu-latest + defaults: + run: + # Hack for enabling color output, see: + # https://github.com/actions/runner/issues/241#issuecomment-842566950 + shell: script -qec "bash --noprofile --norc -eo pipefail {0}" + steps: + - uses: actions/checkout@v2 + - uses: cachix/install-nix-action@v13 + - uses: cachix/cachix-action@v10 + with: + name: postgrest + - name: Install testing scripts + run: nix-env -f default.nix -iA tests withTools + + - name: Run coverage (IO tests and Spec tests against PostgreSQL 13) + run: postgrest-coverage + - name: Upload coverage to codecov + uses: codecov/codecov-action@v2 + with: + files: ./coverage/codecov.json + + - name: Run the spec tests against PostgreSQL 12 + if: always() + run: postgrest-with-postgresql-12 postgrest-test-spec + - name: Run the spec tests against PostgreSQL 11 + if: always() + run: postgrest-with-postgresql-11 postgrest-test-spec + - name: Run the spec tests against PostgreSQL 10 + if: always() + run: postgrest-with-postgresql-10 postgrest-test-spec + - name: Run the spec tests against PostgreSQL 9.6 + if: always() + run: postgrest-with-postgresql-9.6 postgrest-test-spec + - name: Run the spec tests against PostgreSQL 9.5 + if: always() + run: postgrest-with-postgresql-9.5 postgrest-test-spec + + - name: Check the spec tests for idempotence + if: always() + run: postgrest-test-spec-idempotence + + Test-Memory-Nix: + name: Test memory (Nix) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: cachix/install-nix-action@v13 + - uses: cachix/cachix-action@v10 + with: + name: postgrest + - name: Install testing script + run: nix-env -f default.nix -iA memory + - name: Run memory tests + run: postgrest-test-memory + + Build-Linux-Nix: + name: Build Linux static (Nix) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: cachix/install-nix-action@v13 + - uses: cachix/cachix-action@v10 + with: + name: postgrest + authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + + - name: Build static executable + run: nix-build -A postgrestStatic + - name: Save built executable as artifact + uses: actions/upload-artifact@v2 + with: + name: postgrest-linux-static-x64 + path: result/bin/postgrest + if-no-files-found: error + + - name: Build Docker image + run: nix-build -A docker.image --out-link postgrest-docker.tar.gz + - name: Save built Docker image as artifact + uses: actions/upload-artifact@v2 + with: + name: postgrest-docker-x64 + path: postgrest-docker.tar.gz + if-no-files-found: error + + - name: Build and push everything to Cachix (main branch only) + if: ${{ github.ref == 'refs/heads/main' }} + run: | + nix-build + nix-env -f default.nix -iA devTools + postgrest-push-cachix + + Build-Linux-Stack: + name: Build Ubuntu & test (Stack) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Stack working files cache + uses: actions/cache@v2 + with: + path: | + ~/.stack + .stack-work + key: ${{ runner.os }}-${{ hashFiles('stack.yaml.lock') }} + - name: Build with Stack + run: stack build --local-bin-path result --copy-bins + - name: Run Spec tests with Stack + run: | + postgresql_bin="$(find /usr/lib/postgresql -maxdepth 2 -type d -name bin | head -n 1)" + echo "Using PostgreSQL binaries at $postgresql_bin ..." + PATH="$postgresql_bin:$PATH" test/with_tmp_db stack test + - name: Save built executable as artifact + uses: actions/upload-artifact@v2 + with: + name: postgrest-ubuntu-x64 + path: result/postgrest + if-no-files-found: error + + Build-MacOS-Stack: + name: Build MacOS & test (Stack) + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + - name: Stack working files cache + uses: actions/cache@v2 + with: + path: | + ~/.stack + .stack-work + key: ${{ runner.os }}-${{ hashFiles('stack.yaml.lock') }} + - name: Build with Stack + run: stack build --local-bin-path result --copy-bins + - name: Run Spec tests with Stack + run: | + postgresql_bin="$(find /usr/local/Cellar/postgresql -maxdepth 2 -type d -name bin | head -n 1)" + echo "Using PostgreSQL binaries at $postgresql_bin ..." + PATH="$postgresql_bin:$PATH" test/with_tmp_db stack test + - name: Save built executable as artifact + uses: actions/upload-artifact@v2 + with: + name: postgrest-macos-x64 + path: result/postgrest + if-no-files-found: error + + Build-Windows-Stack: + name: Build Windows (Stack) + runs-on: windows-latest + steps: + - uses: actions/checkout@v2 + - name: Stack working files cache + uses: actions/cache@v2 + with: + path: | + ~\AppData\Roaming\stack + ~\AppData\Local\Programs\stack + .stack-work + key: ${{ runner.os }}-${{ hashFiles('stack.yaml.lock') }} + - name: Install dependencies + run: stack exec -- pacman -S mingw64/mingw-w64-x86_64-postgresql --noconfirm + - name: Build with Stack + run: stack build --local-bin-path result --copy-bins + - name: Save built executable as artifact + uses: actions/upload-artifact@v2 + with: + name: postgrest-windows-x64 + path: result/postgrest.exe + if-no-files-found: error + + Get-FreeBSD-CirrusCI: + name: Get FreeBSD build from CirrusCI + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Get FreeBSD executable from CirrusCI + env: + # GITHUB_SHA does weird things for pull request, so we roll our own: + GITHUB_COMMIT: ${{github.event.pull_request.head.sha || github.sha}} + run: .github/get_cirrusci_freebsd + - name: Save executable as artifact + uses: actions/upload-artifact@v2 + with: + name: postgrest-freebsd-x64 + path: postgrest + if-no-files-found: error + + Prepare-Release: + name: Prepare release + if: startsWith(github.ref, 'refs/tags/v') + runs-on: ubuntu-latest + needs: + - Lint-Style + - Test-Nix + - Test-Memory-Nix + - Build-Linux-Nix + - Build-Linux-Stack + - Build-MacOS-Stack + - Build-Windows-Stack + - Get-FreeBSD-CirrusCI + outputs: + version: ${{ steps.Identify-Version.outputs.version }} + isprerelease: ${{ steps.Identify-Version.outputs.isprerelease }} + steps: + - uses: actions/checkout@v2 + - id: Identify-Version + name: Identify the version to be released + run: | + tag_version="${GITHUB_REF##*/}" + cabal_version="$(grep -oP '^version:\s*\K.*' postgrest.cabal)" + + if [ "$tag_version" != "v$cabal_version" ]; then + echo "Tagged version ($tag_version) does not match the one in postgrest.cabal (v$cabal_version). Aborting release..." + exit 1 + else + echo "Version to be released is $cabal_version" + echo "::set-output name=version::$cabal_version" + fi + + if [[ "$cabal_version" != *-* ]]; then + echo "Version is for a full release (no '-' in version)" + else + echo "Version is for a pre-release (version contains a '-', as in v1.0.0-a2)" + echo "::set-output name=isprerelease::1" + fi + - name: Identify changes from CHANGELOG.md + run: | + version="${{ steps.Identify-Version.outputs.version }}" + isprerelease="${{ steps.Identify-Version.outputs.isprerelease }}" + + if [ -n "$isprerelease" ]; then + echo "Getting unreleased changes..." + sed -n "1,/## Unreleased/d;/## \[/q;p" CHANGELOG.md > CHANGES.md + else + echo "Full release (no '-' in version), getting changes for version $version ..." + sed -n "1,/## \[$version\]/d;/## \[/q;p" CHANGELOG.md > CHANGES.md + fi + + echo "Relevant extract from CHANGELOG.md:" + cat CHANGES.md + - name: Save CHANGES.md as artifact + uses: actions/upload-artifact@v2 + with: + name: release-changes + path: CHANGES.md + if-no-files-found: error + + Release-GitHub: + name: Release on GitHub + permissions: write-all + runs-on: ubuntu-latest + needs: Prepare-Release + env: + VERSION: ${{ needs.Prepare-Release.outputs.version }} + steps: + - uses: actions/checkout@v2 + - name: Download all artifacts + uses: actions/download-artifact@v2 + with: + path: artifacts + - name: Create release bundle with archives for all builds + run: | + mkdir -p release-bundle + + tar cfvz "release-bundle/postgrest-v$VERSION-linux-static-x64.tar.gz" \ + -C artifacts/postgrest-linux-static-x64 postgrest + + # No need to release Ubuntu, as the static Linux binary built with Nix + # covers all Linux use-cases + #tar cfvz "release-bundle/postgrest-v$VERSION-ubuntu-x64.tar.gz" \ + # -C artifacts/postgrest-ubuntu-x64 postgrest + + tar cfvz "release-bundle/postgrest-v$VERSION-macos-x64.tar.gz" \ + -C artifacts/postgrest-macos-x64 postgrest + + tar cfvz "release-bundle/postgrest-v$VERSION-freebsd-x64.tar.gz" \ + -C artifacts/postgrest-freebsd-x64 postgrest + + zip "release-bundle/postgrest-v$VERSION-windows-x64.zip" \ + artifacts/postgrest-windows-x64/postgrest.exe + + - name: Save release bundle + uses: actions/upload-artifact@v2 + with: + name: release-bundle + path: release-bundle + if-no-files-found: error + + - name: Publish release on GitHub + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + isprerelease="${{ needs.Prepare-Release.outputs.isprerelease }}" + echo "Releasing version v$VERSION on GitHub (isprerelease=$isprerelease)..." + + gh release delete "v$VERSION" || true + gh release create "v$VERSION" \ + -F artifacts/release-changes/CHANGES.md \ + ${isprerelease:+"--prerelease"} \ + release-bundle/* + + Release-Docker: + name: Release on Docker Hub + runs-on: ubuntu-latest + needs: Prepare-Release + env: + DOCKER_REPO: postgrest + DOCKER_USER: postgrest-bot + VERSION: ${{ needs.Prepare-Release.outputs.version }} + ISPRERELEASE: ${{ needs.Prepare-Release.outputs.isprerelease }} + steps: + - uses: actions/checkout@v2 + - uses: cachix/install-nix-action@v13 + - name: Install release scripts + run: nix-env -f default.nix -iA release + - name: Download Docker image + uses: actions/download-artifact@v2 + with: + name: postgrest-docker-x64 + - name: Publish images on Docker Hub + run: | + docker login -u "$DOCKER_USER" -p "${{ secrets.DOCKER_PASS }}" + docker load -i postgrest-docker.tar.gz + + docker tag postgrest:latest "$DOCKER_REPO/postgrest:v$VERSION" + docker push "$DOCKER_REPO/postgrest:v$VERSION" + + # Only tag 'latest' for full releases + if [[ -z "$ISPRERELEASE" ]]; then + echo "Pushing to 'latest' tag for full release of v$VERSION ..." + docker tag postgrest:latest "$DOCKER_REPO"/postgrest:latest + docker push "$DOCKER_REPO"/postgrest:latest + else + echo "Skipping pushing to 'latest' tag for v$VERSION pre-release..." + fi + - name: Update descriptions on Docker Hub + env: + DOCKER_PASS: ${{ secrets.DOCKER_PASS }} + run: postgrest-release-dockerhub-description diff --git a/default.nix b/default.nix index 98f540b4e..c5e7a9dee 100644 --- a/default.nix +++ b/default.nix @@ -33,7 +33,6 @@ let [ allOverlays.build-toolbox allOverlays.checked-shell-script - allOverlays.ghr allOverlays.gitignore allOverlays.postgresql-default allOverlays.postgresql-legacy @@ -135,10 +134,7 @@ rec { # Scripts for publishing new releases. release = - pkgs.callPackage nix/tools/release { - inherit docker; - postgrest = postgrestStatic; - }; + pkgs.callPackage nix/tools/release { }; # Linting and styling tools. style = diff --git a/nix/overlays/default.nix b/nix/overlays/default.nix index 431636d9c..2e4f8edbd 100644 --- a/nix/overlays/default.nix +++ b/nix/overlays/default.nix @@ -1,7 +1,6 @@ { build-toolbox = import ./build-toolbox; checked-shell-script = import ./checked-shell-script; - ghr = import ./ghr; gitignore = import ./gitignore.nix; haskell-packages = import ./haskell-packages.nix; postgresql-default = import ./postgresql-default.nix; diff --git a/nix/overlays/ghr/default.nix b/nix/overlays/ghr/default.nix deleted file mode 100644 index fc7f1549e..000000000 --- a/nix/overlays/ghr/default.nix +++ /dev/null @@ -1,7 +0,0 @@ -self: super: -# Overlay that adds `ghr`: Upload multiple artifacts to GitHub Release in -# parallel, http://tcnksm.github.io/ghr/ - -{ - ghr = super.callPackage ./ghr.nix { }; -} diff --git a/nix/overlays/ghr/ghr.nix b/nix/overlays/ghr/ghr.nix deleted file mode 100644 index 1d528b30f..000000000 --- a/nix/overlays/ghr/ghr.nix +++ /dev/null @@ -1,18 +0,0 @@ -{ buildGoModule, fetchFromGitHub }: - -buildGoModule rec { - pname = "ghr"; - version = "0.14.0"; - - src = fetchFromGitHub { - rev = "v${version}"; - owner = "tcnksm"; - repo = "ghr"; - sha256 = "1jjc3bwmyw831r1ayic1f1ysh5ggm88aszbndm0swg8byhz56pd4"; - }; - - vendorSha256 = "06cbhsnxv4gisnwrhw61af7rpv2a9slf9z2wbn79r91xzkh51vzr"; - - # Disabling tests, as they require a GitHub API token - doCheck = false; -} diff --git a/nix/tools/release/default.nix b/nix/tools/release/default.nix index 161e3484b..85961aad2 100644 --- a/nix/tools/release/default.nix +++ b/nix/tools/release/default.nix @@ -1,124 +1,10 @@ { buildToolbox , checkedShellScript , curl -, docker -, envsubst , ghr -, git , jq -, postgrest -, runCommand }: let - github = - checkedShellScript - { - name = "postgrest-release-github"; - docs = "Push a new release to GitHub."; - args = [ - "ARG_POSITIONAL_SINGLE([version], [git version tag to make release for])" - "ARG_USE_ENV([GITHUB_TOKEN], [], [GitHub token])" - "ARG_USE_ENV([GITHUB_USERNAME], [], [GitHub user name])" - "ARG_USE_ENV([GITHUB_REPONAME], [], [GitHub repository name])" - ]; - inRootDir = true; - } - '' - # ARG_USE_ENV only adds defaults or docs for environment variables - # We manually implement a required check here - # See also: https://github.com/matejak/argbash/issues/80 - GITHUB_TOKEN="''${GITHUB_TOKEN:?GITHUB_TOKEN is required}" - GITHUB_USERNAME="''${GITHUB_USERNAME:?GITHUB_USERNAME is required}" - GITHUB_REPONAME="''${GITHUB_REPONAME:?GITHUB_REPONAME is required}" - - if test "$_arg_version" = "nightly" - then - suffix=$(${git}/bin/git show -s --format="%cd-%h" --date="format:%Y-%m-%d-%H-%M") - tar cvJf "postgrest-nightly-$suffix-linux-x64-static.tar.xz" \ - -C ${postgrest}/bin postgrest - - ${ghr}/bin/ghr \ - -t "$GITHUB_TOKEN" \ - -u "$GITHUB_USERNAME" \ - -r "$GITHUB_REPONAME" \ - --replace nightly \ - "postgrest-nightly-$suffix-linux-x64-static.tar.xz" - else - changes="$(sed -n "1,/$_arg_version/d;/## \[/q;p" ${../../../CHANGELOG.md})" - - tar cvJf "postgrest-$_arg_version-linux-x64-static.tar.xz" \ - -C ${postgrest}/bin postgrest - - ${ghr}/bin/ghr \ - -t "$GITHUB_TOKEN" \ - -u "$GITHUB_USERNAME" \ - -r "$GITHUB_REPONAME" \ - -b "$changes" \ - --replace "$_arg_version" \ - "postgrest-$_arg_version-linux-x64-static.tar.xz" - fi - ''; - - dockerLogin = - checkedShellScript - { - name = "postgrest-release-docker-login"; - docs = - '' - Log in to Docker Hub using the DOCKER_USER and DOCKER_PASS env vars. - - Those env vars are usually provided by CircleCI. The DOCKER_USER is - not the same as DOCKER_REPO because we use the - https://hub.docker.com/u/postgrestbot account for uploading to dockerhub. - ''; - args = [ - "ARG_USE_ENV([DOCKER_USER], [], [DockerHub user name])" - "ARG_USE_ENV([DOCKER_PASS], [], [DockerHub password])" - ]; - } - '' - # ARG_USE_ENV only adds defaults or docs for environment variables - # We manually implement a required check here - # See also: https://github.com/matejak/argbash/issues/80 - DOCKER_USER="''${DOCKER_USER:?DOCKER_USER is required}" - DOCKER_PASS="''${DOCKER_PASS:?DOCKER_PASS is required}" - - docker login -u "$DOCKER_USER" -p "$DOCKER_PASS" - ''; - - dockerHub = - checkedShellScript - { - name = "postgrest-release-dockerhub"; - docs = "Push a new release to Docker Hub"; - args = [ - "ARG_POSITIONAL_SINGLE([version], [git version tag to tag image with])" - "ARG_USE_ENV([DOCKER_REPO], [], [DockerHub repository])" - ]; - } - '' - # ARG_USE_ENV only adds defaults or docs for environment variables - # We manually implement a required check here - # See also: https://github.com/matejak/argbash/issues/80 - DOCKER_REPO="''${DOCKER_REPO:?DOCKER_REPO is required}" - - docker load -i ${docker.image} - - if test "$_arg_version" = "nightly" - then - suffix=$(${git}/bin/git show -s --format="%cd-%h" --date="format:%Y-%m-%d-%H-%M") - - docker tag postgrest:latest "$DOCKER_REPO/postgrest:nightly-$suffix" - docker push "$DOCKER_REPO/postgrest:nightly-$suffix" - else - docker tag postgrest:latest "$DOCKER_REPO"/postgrest:latest - docker tag postgrest:latest "$DOCKER_REPO/postgrest:$_arg_version" - - docker push "$DOCKER_REPO"/postgrest:latest - docker push "$DOCKER_REPO/postgrest:$_arg_version" - fi - ''; - dockerHubDescription = let description = @@ -145,30 +31,25 @@ let DOCKER_PASS="''${DOCKER_PASS:?DOCKER_PASS is required}" DOCKER_REPO="''${DOCKER_REPO:?DOCKER_REPO is required}" - # Login to Docker Hub and get a token. + echo "Logging in to Docker Hub to get an auth token..." token="$( - ${curl}/bin/curl -s \ + ${curl}/bin/curl --fail -s \ --data-urlencode "username=$DOCKER_USER" \ --data-urlencode "password=$DOCKER_PASS" \ "https://hub.docker.com/v2/users/login/" \ - | ${jq}/bin/jq -r .token + | ${jq}/bin/jq -r .token )" - # Patch both descriptions. - responseCode="$( - ${curl}/bin/curl -s --write-out "%{response_code}" \ - --output /dev/null -H "Authorization: JWT $token" -X PATCH \ - --data-urlencode description@${description} \ - --data-urlencode full_description@${fullDescription} \ - "https://hub.docker.com/v2/repositories/$DOCKER_REPO/postgrest/" - )" - - [ "$responseCode" -eq 200 ] + repo_url="https://hub.docker.com/v2/repositories/$DOCKER_REPO/postgrest/" + echo "Patching both descriptions at $repo_url ..." + ${curl}/bin/curl --fail -X PATCH "$repo_url" \ + -H "Authorization: JWT $token" \ + --data-urlencode description@${description} \ + --data-urlencode full_description@${fullDescription} ''; - in buildToolbox { name = "postgrest-release"; - tools = [ github dockerLogin dockerHub dockerHubDescription ]; + tools = [ dockerHubDescription ]; } diff --git a/shell.nix b/shell.nix index bedab0ccf..e8f34199c 100644 --- a/shell.nix +++ b/shell.nix @@ -2,16 +2,12 @@ # disabled by default. You can activate them by passing arguments to nix-shell, # e.g.: # -# nix-shell --arg release true -# -# This will provide you with a shell where the `postgrest-release-*` scripts -# are available. +# nix-shell --arg docker true # # We highly recommend that use the PostgREST binary cache by installing cachix # (https://app.cachix.org/) and running `cachix use postgrest`. { docker ? false , memory ? false -, release ? false }: let postgrest = @@ -31,10 +27,10 @@ let postgrest.style postgrest.tests postgrest.withTools + postgrest.release ] ++ lib.optional docker postgrest.docker - ++ lib.optional memory postgrest.memory - ++ lib.optional release postgrest.release; + ++ lib.optional memory postgrest.memory; in lib.overrideDerivation postgrest.env (