Skip to content

Commit

Permalink
Add GitHub actions file (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinThrift committed Feb 23, 2020
1 parent 27b642e commit b624694
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 62 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: build

on:
push:
branches: master
repository_dispatch:

jobs:
build:
env:
GIT_NAME: "GitHub actions"
GIT_EMAIL: "[email protected]"
SOURCE_DIR: "build"
DEPLOY_BRANCH: "master"
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO_NAME: ${{ github.event.repository.name }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '10.x'
- name: Install
run: npm install
- name: Build
run: npm run build
- name: CNAME
run: echo "hannoverjs.com" > ./src/CNAME
- name: Deploy
run: ./deploy.sh

20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

58 changes: 16 additions & 42 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
set -e

GHA_BRANCH=${GITHUB_REF#refs/heads/}

# Deploy built docs to this branch
TARGET_BRANCH=gh-pages

Expand All @@ -11,57 +13,29 @@ fi

REPO=$(git config remote.origin.url)

if [ -n "$TRAVIS_BUILD_ID" ]; then
# When running on Travis we need to use SSH to deploy to GitHub
#
# The following converts the repo URL to an SSH location,
# decrypts the SSH key and sets up the Git config with
# the correct user name and email (globally as this is a
# temporary travis environment)
#
# Set the following environment variables in the travis configuration (.travis.yml)
#
# DEPLOY_BRANCH - The only branch that Travis should deploy from
# ENCRYPTION_LABEL - The label assigned when encrypting the SSH key using travis encrypt-file
# GIT_NAME - The Git user name
# GIT_EMAIL - The Git user email
#
echo DEPLOY_BRANCH: $DEPLOY_BRANCH
echo ENCRYPTION_LABEL: $ENCRYPTION_LABEL
echo GIT_NAME: $GIT_NAME
echo GIT_EMAIL: $GIT_EMAIL
if [ "$TRAVIS_BRANCH" != "$DEPLOY_BRANCH" ]; then
echo "Travis should only deploy from the DEPLOY_BRANCH ($DEPLOY_BRANCH) branch"
echo DEPLOY_BRANCH: $DEPLOY_BRANCH
echo GIT_NAME: $GIT_NAME
echo GIT_EMAIL: $GIT_EMAIL
echo GHA_BRANCH: $GHA_BRANCH
if [ "$GHA_BRANCH" != "$DEPLOY_BRANCH" ]; then
echo "Actions should only deploy from the DEPLOY_BRANCH ($DEPLOY_BRANCH) branch"
exit 0
else
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
echo "Travis should not deploy from pull requests"
exit 0
else
# switch both git and https protocols as we don't know which travis
# is using today (it changed!)
REPO=${REPO/git:\/\/github.com\//git@github.com:}
REPO=${REPO/https:\/\/github.com\//git@github.com:}

chmod 600 $SSH_KEY
eval `ssh-agent -s`
ssh-add $SSH_KEY
git config --global user.name "$GIT_NAME"
git config --global user.email "$GIT_EMAIL"
fi
fi
fi

REPO="https://RobinThrift:${GITHUB_TOKEN}@github.com/HannoverJS/website.git"

git config --global user.name "$GIT_NAME"
git config --global user.email "$GIT_EMAIL"

REPO_NAME=$(basename $REPO)
TARGET_DIR=$(mktemp -d /tmp/$REPO_NAME.XXXX)
REV=$(git rev-parse HEAD)
git clone --branch ${TARGET_BRANCH} ${REPO} ${TARGET_DIR}
rsync -rt --delete --exclude=".git" --exclude=".travis.yml" $SOURCE_DIR/ $TARGET_DIR/
rsync -rt --delete --exclude=".git" --exclude=".github" $SOURCE_DIR/ $TARGET_DIR/
cd $TARGET_DIR
echo "hannoverjs.de" > CNAME
git add -A .
git commit --allow-empty -m "auto-build: build from $REV at $(date)"
git push $REPO $TARGET_BRANCH
git remote add gh $REPO
git push gh $TARGET_BRANCH

git config --global user.name "$GIT_NAME"
git config --global user.email "$GIT_EMAIL"
Binary file removed travis_rsa.enc
Binary file not shown.

0 comments on commit b624694

Please sign in to comment.