Browse Source

Automatically publish Github releases on tag push (#503)

Andrey Novikov 4 years ago
parent
commit
19f430409d
1 changed files with 40 additions and 0 deletions
  1. 40 0
      .circleci/config.yml

+ 40 - 0
.circleci/config.yml

@@ -19,6 +19,19 @@ workflows:
               go_version: ["1.15", "1.14", "1.13"]
               vips_version: ["8.10", "8.9", "8.8"]
 
+  release:
+    jobs:
+      - checkout_code:
+          filters: &release_tags_filter
+            branches:
+              ignore: /.*/
+            tags:
+              only: /^v\d+\.\d+\.\d+.*/
+      - publish_github_release:
+          requires:
+            - checkout_code # to grab changes from CHANGELOG
+          filters: *release_tags_filter
+
 executors:
   imgproxy:
     docker:
@@ -111,3 +124,30 @@ jobs:
           key: go-modules-{{ checksum "go.sum" }}
           paths:
             - "/go/pkg/mod"
+
+  publish_github_release:
+    executor: imgproxy
+    steps:
+      - attach_workspace:
+          at: .
+      - install_go:
+          go_version: "1.14"
+      - run:
+          name: Install github-release tool
+          command: go get github.com/github-release/github-release
+      - run:
+          name: Upload GitHub release
+          command: |
+            # Extract changelog entries between this and previous version headers
+            escaped_version=$(echo ${CIRCLE_TAG#v} | sed -e 's/[]\/$*.^[]/\\&/g')
+            description_body=$(awk "BEGIN{inrelease=0} /## \[${escaped_version}\]/{inrelease=1;next} /## \[[0-9]+\.[0-9]+\.[0-9]+\]/{inrelease=0;exit} {if (inrelease) print}" CHANGELOG.md)
+            # Add pre-release option if tag name has any suffix after vMAJOR.MINOR.PATCH
+            [[ ${CIRCLE_TAG} =~ ^v[0-9]+\.[0-9]+\.[0-9]+.+ ]] && prerelease="--pre-release"
+            # Create release!
+            github-release release \
+              --user ${CIRCLE_PROJECT_USERNAME} \
+              --repo ${CIRCLE_PROJECT_REPONAME} \
+              --tag ${CIRCLE_TAG} \
+              --name ${CIRCLE_TAG} \
+              --description "${description_body}" \
+              $prerelease