From 0e0e18dc9886c8b68f8bce3d1918bb273a34a1cd Mon Sep 17 00:00:00 2001 From: monacoremo <59358383+monacoremo@users.noreply.github.com> Date: Sat, 18 Sep 2021 17:45:07 +0200 Subject: [PATCH] ci: Fix triggering events and release actions * 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 --- .github/workflows/ci.yaml | 45 ++++++++++++++++++++++++++------------- postgrest.cabal | 2 +- src/PostgREST/Version.hs | 30 ++++++++++++++++++-------- 3 files changed, 52 insertions(+), 25 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ea9953f93c..e8209b5ec3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,7 +1,14 @@ name: CI + on: - - push - - pull_request + push: + branches: + - main + tags: + - v* + pull_request: + branches: + - main jobs: Lint-Style: @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/postgrest.cabal b/postgrest.cabal index 2ef7635102..5531d26f50 100644 --- a/postgrest.cabal +++ b/postgrest.cabal @@ -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 diff --git a/src/PostgREST/Version.hs b/src/PostgREST/Version.hs index 490ddde84c..0d8ca669e2 100644 --- a/src/PostgREST/Version.hs +++ b/src/PostgREST/Version.hs @@ -1,5 +1,4 @@ {-# LANGUAGE TemplateHaskell #-} -{-# OPTIONS_GHC -fno-warn-type-defaults #-} module PostgREST.Version ( docsVersion , prettyVersion @@ -7,23 +6,36 @@ module PostgREST.Version 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