Skip to content

Commit 7f3729f

Browse files
committed
Add GitHub actions file (#44)
1 parent 27b642e commit 7f3729f

File tree

4 files changed

+47
-62
lines changed

4 files changed

+47
-62
lines changed

.github/workflows/main.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches: master
6+
repository_dispatch:
7+
8+
jobs:
9+
build:
10+
env:
11+
GIT_NAME: "GitHub actions"
12+
GIT_EMAIL: "[email protected]"
13+
SOURCE_DIR: "build"
14+
DEPLOY_BRANCH: "master"
15+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16+
REPO_NAME: ${{ github.event.repository.name }}
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v2
20+
- uses: actions/setup-node@v1
21+
with:
22+
node-version: '10.x'
23+
- name: Install
24+
run: npm install
25+
- name: Build
26+
run: npm run build
27+
- name: CNAME
28+
run: echo "hannoverjs.com" > ./src/CNAME
29+
- name: Deploy
30+
run: ./deploy.sh
31+

.travis.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

deploy.sh

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash
22
set -e
33

4+
GHA_BRANCH=${GITHUB_REF#refs/heads/}
5+
46
# Deploy built docs to this branch
57
TARGET_BRANCH=gh-pages
68

@@ -11,57 +13,29 @@ fi
1113

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

14-
if [ -n "$TRAVIS_BUILD_ID" ]; then
15-
# When running on Travis we need to use SSH to deploy to GitHub
16-
#
17-
# The following converts the repo URL to an SSH location,
18-
# decrypts the SSH key and sets up the Git config with
19-
# the correct user name and email (globally as this is a
20-
# temporary travis environment)
21-
#
22-
# Set the following environment variables in the travis configuration (.travis.yml)
23-
#
24-
# DEPLOY_BRANCH - The only branch that Travis should deploy from
25-
# ENCRYPTION_LABEL - The label assigned when encrypting the SSH key using travis encrypt-file
26-
# GIT_NAME - The Git user name
27-
# GIT_EMAIL - The Git user email
28-
#
29-
echo DEPLOY_BRANCH: $DEPLOY_BRANCH
30-
echo ENCRYPTION_LABEL: $ENCRYPTION_LABEL
31-
echo GIT_NAME: $GIT_NAME
32-
echo GIT_EMAIL: $GIT_EMAIL
33-
if [ "$TRAVIS_BRANCH" != "$DEPLOY_BRANCH" ]; then
34-
echo "Travis should only deploy from the DEPLOY_BRANCH ($DEPLOY_BRANCH) branch"
16+
echo DEPLOY_BRANCH: $DEPLOY_BRANCH
17+
echo GIT_NAME: $GIT_NAME
18+
echo GIT_EMAIL: $GIT_EMAIL
19+
echo GHA_BRANCH: $GHA_BRANCH
20+
if [ "$GHA_BRANCH" != "$DEPLOY_BRANCH" ]; then
21+
echo "Actions should only deploy from the DEPLOY_BRANCH ($DEPLOY_BRANCH) branch"
3522
exit 0
36-
else
37-
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
38-
echo "Travis should not deploy from pull requests"
39-
exit 0
40-
else
41-
# switch both git and https protocols as we don't know which travis
42-
# is using today (it changed!)
43-
REPO=${REPO/git:\/\/github.com\//git@github.com:}
44-
REPO=${REPO/https:\/\/github.com\//git@github.com:}
45-
46-
chmod 600 $SSH_KEY
47-
eval `ssh-agent -s`
48-
ssh-add $SSH_KEY
49-
git config --global user.name "$GIT_NAME"
50-
git config --global user.email "$GIT_EMAIL"
51-
fi
52-
fi
5323
fi
24+
25+
REPO="https://RobinThrift:${GH_TOKEN}@github.com/HannoverJS/website.git"
26+
27+
git config --global user.name "$GIT_NAME"
28+
git config --global user.email "$GIT_EMAIL"
5429

5530
REPO_NAME=$(basename $REPO)
5631
TARGET_DIR=$(mktemp -d /tmp/$REPO_NAME.XXXX)
5732
REV=$(git rev-parse HEAD)
5833
git clone --branch ${TARGET_BRANCH} ${REPO} ${TARGET_DIR}
59-
rsync -rt --delete --exclude=".git" --exclude=".travis.yml" $SOURCE_DIR/ $TARGET_DIR/
34+
rsync -rt --delete --exclude=".git" --exclude=".github" $SOURCE_DIR/ $TARGET_DIR/
6035
cd $TARGET_DIR
6136
echo "hannoverjs.de" > CNAME
6237
git add -A .
6338
git commit --allow-empty -m "auto-build: build from $REV at $(date)"
64-
git push $REPO $TARGET_BRANCH
39+
git remote add gh $REPO
40+
git push gh $TARGET_BRANCH
6541

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

travis_rsa.enc

-3.34 KB
Binary file not shown.

0 commit comments

Comments
 (0)