Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nightly builds #1648

Merged
merged 10 commits into from
Nov 11, 2020
15 changes: 9 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,14 @@ jobs:
# Publish a new release. This only runs when a release is tagged (see
# workflow below).
release:
docker:
- image: nixos/nix:2.3
machine: true
steps:
- checkout
- run:
name: Install Nix
command: |
curl -L https://nixos.org/nix/install | sh
echo "source $HOME/.nix-profile/etc/profile.d/nix.sh" >> $BASH_ENV
- run:
name: Install and use the Cachix binary cache
command: |
Expand All @@ -136,14 +140,13 @@ jobs:
command: |
export GITHUB_USERNAME="$CIRCLE_PROJECT_USERNAME"
export GITHUB_REPONAME="$CIRCLE_PROJECT_REPONAME"
postgrest-release-github
- setup_remote_docker
postgrest-release-github $CIRCLE_TAG
- run:
name: Publish Docker images
command: |
export DOCKER_REPO=postgrest
docker login -u $DOCKER_USER -p $DOCKER_PASS
postgrest-release-dockerhub
postgrest-docker-login
postgrest-release-dockerhub $CIRCLE_TAG
postgrest-release-dockerhubdescription

# Build everything in default.nix, push to the Cachix binary cache and run tests
Expand Down
26 changes: 18 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,24 @@ jobs:
then
echo 'No tag pushed. Skipping release.'
else
OWNER="$(echo "$TRAVIS_REPO_SLUG" | cut -f1 -d/)"
REPO="$(echo "$TRAVIS_REPO_SLUG" | cut -f2 -d/)"
START=$(echo $TRAVIS_TAG | cut -c2-)
END='## \['
BODY=$(sed -n "1,/$START/d;/$END/q;p" CHANGELOG.md)
strip postgrest
tar cJf postgrest-$TRAVIS_TAG-osx.tar.xz postgrest
ghr -t $GITHUB_TOKEN -u $OWNER -r $REPO -b "$BODY"--replace $TRAVIS_TAG postgrest-$TRAVIS_TAG-osx.tar.xz
owner="$(echo "$TRAVIS_REPO_SLUG" | cut -f1 -d/)"
repo="$(echo "$TRAVIS_REPO_SLUG" | cut -f2 -d/)"
if test $TRAVIS_TAG = "nightly"
then
date=$(date +'%F')
sha=$(echo $TRAVIS_COMMIT | head -c7)
suffix=$date-$sha
strip postgrest
tar cJf postgrest-nightly-$suffix-osx.tar.xz postgrest
ghr -t $GITHUB_TOKEN -u $owner -r $repo --replace nightly postgrest-nightly-$suffix-osx.tar.xz
else
start=$TRAVIS_TAG
end='## \['
body=$(sed -n "1,/$start/d;/$end/q;p" CHANGELOG.md)
strip postgrest
tar cJf postgrest-$TRAVIS_TAG-osx.tar.xz postgrest
ghr -t $GITHUB_TOKEN -u $owner -r $repo -b "$body"--replace $TRAVIS_TAG postgrest-$TRAVIS_TAG-osx.tar.xz
fi
fi

- name: Code Coverage
Expand Down
15 changes: 13 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,16 @@ artifacts:
- path: postgrest.exe

deploy_script:
- IF DEFINED APPVEYOR_REPO_TAG_NAME 7z a -tzip postgrest-%APPVEYOR_REPO_TAG_NAME%-windows-x64.zip postgrest.exe
- IF DEFINED APPVEYOR_REPO_TAG_NAME bash -lc " exec 0</dev/null && cd $APPVEYOR_BUILD_FOLDER && ghr -t $GITHUB_TOKEN -u $APPVEYOR_ACCOUNT_NAME -r $APPVEYOR_PROJECT_NAME -b \"$(sed -n \"1,/$(echo $APPVEYOR_REPO_TAG_NAME | cut -c2-)/d;/## \[/q;p\" CHANGELOG.md)\" --replace $APPVEYOR_REPO_TAG_NAME postgrest-$APPVEYOR_REPO_TAG_NAME-windows-x64.zip"
## set the env vars outside of the IF because that doesn't work: https://stackoverflow.com/questions/9102422/windows-batch-set-inside-if-not-working
- set DATE=%APPVEYOR_REPO_COMMIT_TIMESTAMP:~0,10%
- set SHA=%APPVEYOR_REPO_COMMIT:~0,7%
- set SUFFIX=%DATE%-%SHA%
- IF DEFINED APPVEYOR_REPO_TAG_NAME (
IF "%APPVEYOR_REPO_TAG_NAME%"=="nightly" (
7z a -tzip postgrest-nightly-%SUFFIX%-windows-x64.zip postgrest.exe &&
bash -lc "exec 0</dev/null && cd $APPVEYOR_BUILD_FOLDER && ghr -t $GITHUB_TOKEN -u $APPVEYOR_ACCOUNT_NAME -r $APPVEYOR_PROJECT_NAME --replace nightly postgrest-nightly-$SUFFIX-windows-x64.zip"
) ELSE (
7z a -tzip postgrest-%APPVEYOR_REPO_TAG_NAME%-windows-x64.zip postgrest.exe &&
bash -lc "exec 0</dev/null && cd $APPVEYOR_BUILD_FOLDER && ghr -t $GITHUB_TOKEN -u $APPVEYOR_ACCOUNT_NAME -r $APPVEYOR_PROJECT_NAME -b \"`sed -n \"1,/$APPVEYOR_REPO_TAG_NAME/d;/## \[/q;p\" CHANGELOG.md`\" --replace $APPVEYOR_REPO_TAG_NAME postgrest-$APPVEYOR_REPO_TAG_NAME-windows-x64.zip"
)
)
48 changes: 26 additions & 22 deletions nix/release/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,36 @@ let
# Version from the postgrest.cabal file (gotten with callCabal2nix).
version = postgrest.version;

# Set of files that will be published in the GitHub release.
releaseFiles =
runCommand "postgrest-release-files"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@monacoremo In case you're wondering. I deleted this nix function because I couldn't figure out how to pass a bash argument to it in writeShellScriptBin "postgrest-release-github". My nix-fu isn't that good 😄.

{ inherit postgrest version; }
''
set -euo pipefail

mkdir -p $out

tar cvJf "$out"/postgrest-v"$version"-linux-x64-static.tar.xz \
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the v prefix from v$version in the scripts. This means that the changelog versions will now need a v prefix for sed to pick the changes and then serve as the body for the release(done with ghr).

-C "$postgrest"/bin postgrest
'';

# Script for publishing a new release on GitHub.
github =
writeShellScriptBin "postgrest-release-github"
''
set -euo pipefail

changes="$(sed -n "1,/${version}/d;/## \[/q;p" ${../../CHANGELOG.md})"
version=$1

changes="$(sed -n "1,/$version/d;/## \[/q;p" ${../../CHANGELOG.md})"

tar cvJf postgrest-$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 v${version} \
${releaseFiles}
--replace $version \
postgrest-$version-linux-x64-static.tar.xz
'';

# Wrapper for login with docker. $DOCKER_USER/$DOCKER_PASS vars come from 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.
dockerLogin =
writeShellScriptBin "postgrest-docker-login"
''
set -euo pipefail

docker login -u $DOCKER_USER -p $DOCKER_PASS
'';

# Script for publishing a new release on Docker Hub.
Expand All @@ -48,13 +50,15 @@ let
''
set -euo pipefail

version=$1

docker load -i ${docker.image}

docker tag postgrest:latest "$DOCKER_REPO"/postgrest:latest
docker tag postgrest:latest "$DOCKER_REPO"/postgrest:v${version}
docker tag postgrest:latest "$DOCKER_REPO"/postgrest:$version

docker push "$DOCKER_REPO"/postgrest:latest
docker push "$DOCKER_REPO"/postgrest:v${version}
docker push "$DOCKER_REPO"/postgrest:$version
'';

# Script for updating the repository description on Docker Hub.
Expand All @@ -72,9 +76,9 @@ let

# Login to Docker Hub and get a token.
token="$(
${curl}/bin/curl -sH "Content-Type: application/json" \
--data-urlencode "username=$DOCKER_USERNAME" \
--data-urlencode "password=$DOCKER_PASSWORD" \
${curl}/bin/curl -s \
--data-urlencode "username=$DOCKER_USER" \
--data-urlencode "password=$DOCKER_PASS" \
"https://hub.docker.com/v2/users/login/" \
| ${jq}/bin/jq -r .token
)"
Expand All @@ -97,5 +101,5 @@ let
in
buildEnv {
name = "postgrest-release";
paths = [ github dockerHub dockerHubDescription ];
paths = [ github dockerLogin dockerHub dockerHubDescription ];
}