Skip to content

Commit

Permalink
Feat/first version (#8)
Browse files Browse the repository at this point in the history
feat(): (#1) add first version
  • Loading branch information
AndreasAugustin authored Jun 12, 2020
1 parent 7e1fb15 commit 965a1a0
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.github/
.devcontainer/
.dependabot/
File renamed without changes.
19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: test

on: [push]

jobs:

test-implementation-job:

runs-on: ubuntu-latest

steps:
# To use this repository's private action, you must check out the repository
- name: Checkout
uses: actions/checkout@v2
- name: Test action step
uses: ./ # Uses an action in the root directory
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
source_repo_path: AndreasAugustin/template.git
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
#######################################
# image for dev build environment
######################################
FROM alpine:3.12.0 as DEV
FROM golang:1.14-alpine as DEV

# install packages
RUN apk add --update --no-cache bash make git zsh curl tmux
RUN apk add --update --no-cache bash make git zsh curl tmux musl build-base

# Make zsh your default shell for tmux
RUN echo "set-option -g default-shell /bin/zsh" >> /root/.tmux.conf

# install oh-my-zsh
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

RUN git clone https://github.com/cli/cli.git gh-cli \
&& cd gh-cli \
&& make \
&& mv ./bin/gh /usr/local/bin/

WORKDIR /app

#######################################
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# template

![Lint](https://github.com/AndreasAugustin/template/workflows/Lint/badge.svg)
![Lint](https://github.com/AndreasAugustin/actions-template-sync/workflows/Lint/badge.svg)

## DEV

Expand Down
19 changes: 19 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: 'Template sync'
description: 'Synchronises changes of the template repository'
author: 'AndreasAugustin'
branding:
icon: cloud
color: green
inputs:
github_token:
description: 'Token for the repo. Can be passed in using $\{{ secrets.GITHUB_TOKEN }}'
required: true
source_repo_path:
description: 'Repository path of the template'
required: true
runs:
using: 'docker'
image: 'src/Dockerfile'
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
SOURCE_REPO_PATH: ${{ inputs.source_repo_path }}
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ services:
target: DEV
volumes:
- .:/app/
- ~/.gitconfig:/root/.gitconfig:ro
docs:
build:
context: .
Expand Down
21 changes: 21 additions & 0 deletions src/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM golang:1.14-alpine
# labels
LABEL \
"name"="GitHub template sync" \
"homepage"="https://github.com/marketplace/actions/github-template-sync" \
"repository"="https://github.com/AndreasAugustin/actions-template-sync" \
"maintainer"="Andreas Augustin <[email protected]>"

# install packages
RUN apk add --update --no-cache bash make git zsh curl tmux musl build-base

RUN git clone https://github.com/cli/cli.git gh-cli \
&& cd gh-cli \
&& make \
&& mv ./bin/gh /usr/local/bin/

ADD *.sh /bin/
RUN chmod +x /bin/entrypoint.sh \
&& chmod +x /bin/sync_template.sh

ENTRYPOINT ["/bin/entrypoint.sh"]
20 changes: 20 additions & 0 deletions src/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#! /usr/bin/env bash
set -e

[ -z "${GITHUB_TOKEN}" ] && {
echo "Missing input 'github_token: \${{ secrets.GITHUB_TOKEN }}'.";
exit 1;
};

if [[ -z "${SOURCE_REPO_PATH}" ]]; then
echo "Missing input 'source_repo_path: \${{ input.source_repo_path }}'.;"
exit 1
fi

SOURCE_REPO="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${SOURCE_REPO_PATH}"

echo "set git global configuration"
git config --global user.email "[email protected]@"
git config --global user.name "actions-template-sync"

source sync_template.sh
26 changes: 26 additions & 0 deletions src/sync_template.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#! /usr/bin/env bash
set -e

if [[ -z "${SOURCE_REPO}" ]]; then
echo "Error: Missing env variable 'SOURCE_REPO'" >&2;
exit 1;
fi

if ! [ -x "$(command -v gh)" ]; then
echo "Error: github-cli gh is not installed. 'https://github.com/cli/cli'" >&2;
exit 1;
fi

NEW_BRANCH="chore/template_sync"

echo "start sync"
echo "create new branch from default branch with name ${NEW_BRANCH}"
git checkout -b ${NEW_BRANCH}
echo "pull changes from template"
git pull "${SOURCE_REPO}" --allow-unrelated-histories
git add .
git commit -m "chore(template): merge template changes :up:"
echo "push changes"
git push --set-upstream origin "${NEW_BRANCH}"
echo "create pull request"
gh pr create -b master -f -l chore

0 comments on commit 965a1a0

Please sign in to comment.