Skip to content

Commit

Permalink
ci: Fix triggering events and release actions
Browse files Browse the repository at this point in the history
* Run CI only on pull requests, push to main and push
  to tags matching v*. This avoids running the CI more than
  once for a single user action
* Change pre-releases, which are now identified by a version
  number with 4 components (e.g., 1.1.1.1)
* Change how release artifacts are packaged, ensuring they
  are executable and compressed with xz
  • Loading branch information
monacoremo committed Sep 21, 2021
1 parent 243e4f0 commit 0e0e18d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 25 deletions.
45 changes: 30 additions & 15 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
name: CI

on:
- push
- pull_request
push:
branches:
- main
tags:
- v*
pull_request:
branches:
- main

jobs:
Lint-Style:
Expand Down Expand Up @@ -236,10 +243,10 @@ jobs:
echo "::set-output name=version::$cabal_version"
fi
if [[ "$cabal_version" != *-* ]]; then
echo "Version is for a full release (no '-' in version)"
if [[ "$cabal_version" != *.*.*.* ]]; then
echo "Version is for a full release (version does not have four components)"
else
echo "Version is for a pre-release (version contains a '-', as in v1.0.0-a2)"
echo "Version is for a pre-release (version has four components, e.g., 1.1.1.1)"
echo "::set-output name=isprerelease::1"
fi
- name: Identify changes from CHANGELOG.md
Expand Down Expand Up @@ -279,22 +286,24 @@ jobs:
path: artifacts
- name: Create release bundle with archives for all builds
run: |
find artifacts -type f -iname postgrest -exec chmod +x {} \;
mkdir -p release-bundle
tar cfvz "release-bundle/postgrest-v$VERSION-linux-static-x64.tar.gz" \
tar cJvf "release-bundle/postgrest-v$VERSION-linux-static-x64.tar.xz" \
-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" \
#tar cfJv "release-bundle/postgrest-v$VERSION-ubuntu-x64.tar.xz" \
# -C artifacts/postgrest-ubuntu-x64 postgrest
tar cfvz "release-bundle/postgrest-v$VERSION-macos-x64.tar.gz" \
tar cJvf "release-bundle/postgrest-v$VERSION-macos-x64.tar.xz" \
-C artifacts/postgrest-macos-x64 postgrest
tar cfvz "release-bundle/postgrest-v$VERSION-freebsd-x64.tar.gz" \
tar cJvf "release-bundle/postgrest-v$VERSION-freebsd-x64.tar.xz" \
-C artifacts/postgrest-freebsd-x64 postgrest
zip "release-bundle/postgrest-v$VERSION-windows-x64.zip" \
artifacts/postgrest-windows-x64/postgrest.exe
Expand All @@ -317,7 +326,7 @@ jobs:
-F artifacts/release-changes/CHANGES.md \
${isprerelease:+"--prerelease"} \
release-bundle/*
Release-Docker:
name: Release on Docker Hub
runs-on: ubuntu-latest
Expand Down Expand Up @@ -355,4 +364,10 @@ jobs:
- name: Update descriptions on Docker Hub
env:
DOCKER_PASS: ${{ secrets.DOCKER_PASS }}
run: postgrest-release-dockerhub-description
run: |
if [[ -z "$ISPRERELEASE" ]]; then
echo "Updating description on Docker Hub..."
postgrest-release-dockerhub-description
else
echo "Skipping updating description for pre-release..."
fi
2 changes: 1 addition & 1 deletion postgrest.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: postgrest
version: 9.0.0-a1
version: 9.0.0.20210921
synopsis: REST API for any Postgres database
description: Reads the schema of a PostgreSQL database and creates RESTful routes
for the tables and views, supporting all HTTP verbs that security
Expand Down
30 changes: 21 additions & 9 deletions src/PostgREST/Version.hs
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
module PostgREST.Version
( docsVersion
, prettyVersion
) where

import qualified Data.Text as T

import Data.Version (versionBranch)
import Data.Version (showVersion, versionBranch)
import Development.GitRev (gitHash)
import Paths_postgrest (version)

import Protolude


-- | User friendly version number
-- | User friendly version number such as '1.1.1'.
-- Pre-release versions are tagged as such, e.g., '1.1.1.1 (pre-release)'.
-- If a git hash is available, it's added to the version, e.g., '1.1.1 (abcdef0)'.
prettyVersion :: Text
prettyVersion =
T.intercalate "." (map show $ versionBranch version) <> gitRev
T.pack (showVersion version) <> preRelease <> gitRev
where
gitRev =
if $(gitHash) == "UNKNOWN"
then mempty
else " (" <> T.take 7 $(gitHash) <> ")"
if $(gitHash) == ("UNKNOWN" :: Text) then
mempty
else
" (" <> T.take 7 $(gitHash) <> ")"
preRelease = if isPreRelease then " (pre-release)" else mempty

-- | Version number used in docs

-- | Version number used in docs.
-- Uses only the two first components of the version. Example: 'v1.1'
docsVersion :: Text
docsVersion = "v" <> T.dropEnd 1 (T.dropWhileEnd (/= '.') prettyVersion)
docsVersion =
"v" <> (T.intercalate "." . map show . take 2 $ versionBranch version)


-- | Versions with four components (e.g., '1.1.1.1') are treated as pre-releases.
isPreRelease :: Bool
isPreRelease =
length (versionBranch version) == 4

0 comments on commit 0e0e18d

Please sign in to comment.