This is an automated email from the ASF dual-hosted git repository.

zregvart pushed a commit to branch pr/deployment
in repository https://gitbox.apache.org/repos/asf/camel-website.git

commit 326feb5eae42babdb31025408dc7d23b14a0d76e
Author: Zoran Regvart <zregv...@apache.org>
AuthorDate: Sun Mar 3 16:19:37 2019 +0100

    chore: GitHub deployments
    
    Creates a GitHub deployment for previews and staging environment.
---
 .github/action-website/publish | 44 ++++++++++++++++++++++++++++++++++++++----
 .github/main.workflow          | 14 +++-----------
 2 files changed, 43 insertions(+), 15 deletions(-)

diff --git a/.github/action-website/publish b/.github/action-website/publish
index fa7cacf..461727b 100755
--- a/.github/action-website/publish
+++ b/.github/action-website/publish
@@ -2,17 +2,53 @@
 
 set -euxo pipefail
 
-REV=$(cd "$GITHUB_WORKSPACE" && git rev-parse --short HEAD)
+IS_PULL_REQUEST=$(jq -r .pull_request $GITHUB_EVENT_PATH)
+REF=$(jq -r .ref $GITHUB_EVENT_PATH)
+ENVIRONMENT="preview"
+TRANSIENT="true"
+
+if [ "$IS_PULL_REQUEST" != "null" ]; then
+    DEST_DIR="preview/PR/$(jq .pull_request.number $GITHUB_EVENT_PATH)"
+elif [ "$REF" != "ref/heads/master" ]; then
+    DEST_DIR="preview/branch/${REF##*/}"
+else
+    DEST_DIR=.
+    ENVIRONMENT="staging"
+    TRANSIENT="false"
+fi
 
 PUBLISH_DIR=$(mktemp -d /tmp/publish.XXXXXXXX)
 cd $PUBLISH_DIR
 
 git clone -b asf-site https://github.com/apache/camel-website.git .
 git config user.email d...@camel.apache.org
-git config user.name "$GITHUB_ACTOR"
+git config user.name $GITHUB_ACTOR
+mkdir -p $DEST_DIR
+cd $DEST_DIR
 git rm -r --ignore-unmatch *
-cp -Rvn "${GITHUB_WORKSPACE}/public/"* .
+cp -Rvn $GITHUB_WORKSPACE/public/* .
 git add .
-git commit -m "Website updated to ${REV}"
+git commit -m "Website updated to $(git rev-parse --short HEAD)"
 git push origin asf-site
 
+URI=https://api.github.com
+API_HEADER="Accept: application/vnd.github.ant-man-preview+json"
+AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}"
+
+IFS='' read -r -d '' DEPLOYMENT_JSON<<"EOF"
+{
+  "ref": "${REF}",
+  "auto_merge": false,
+  "environment": "${ENVIRONMENT}"
+  "description": "Website built and deployed to ${ENVIRONMENT} environment",
+  "transient": ${TRANSIENT},
+  "payload": "https://apache.camel.com/staging/${DEST_DIR}";,
+  "description": "Deploy request from hubot"
+}
+EOF
+
+curl -XPOST -sSL \
+    -H "${AUTH_HEADER}" \
+    -H "${API_HEADER}" \
+    -d "${DEPLOYMENT_JSON}" \
+    "${URI}/repos/apache/camel-website"
diff --git a/.github/main.workflow b/.github/main.workflow
index e0360e5..7bdd9c1 100644
--- a/.github/main.workflow
+++ b/.github/main.workflow
@@ -5,26 +5,18 @@ workflow "Build and publish the website" {
 
 action "Build theme" {
   uses = "./.github/action-website"
-  runs = "yarn"
-  args = "--non-interactive --frozen-lockfile --cwd antora-ui-camel"
+  runs = ["sh", "-c", "yarn --non-interactive --frozen-lockfile --cwd 
antora-ui-camel install && yarn --non-interactive --frozen-lockfile --cwd 
antora-ui-camel build"]
 }
 
 action "Build website" {
   uses = "./.github/action-website"
   needs = ["Build theme"]
-  runs = "yarn"
-  args = "--non-interactive --frozen-lockfile"
-}
-
-action "On master branch" {
-  uses = "actions/bin/filter@d820d56839906464fb7a57d1b4e1741cf5183efa"
-  needs = ["Build website"]
-  args = "branch master"
+  runs = ["sh", "-c", "yarn --non-interactive --frozen-lockfile install && 
yarn --non-interactive --frozen-lockfile build"]
 }
 
 action "Publish" {
   uses = "./.github/action-website"
-  needs = ["On master branch"]
+  needs = ["Build website"]
   runs = "publish"
   secrets = ["GITHUB_TOKEN"]
 }

Reply via email to