diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3a42fca --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.github/ +.devcontainer/ +.dependabot/ diff --git a/SECURITY.md b/.github/SECURITY.md similarity index 100% rename from SECURITY.md rename to .github/SECURITY.md diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..3bf6d3b --- /dev/null +++ b/.github/workflows/test.yml @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/Dockerfile b/Dockerfile index f8404d9..0fd0594 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,10 @@ ####################################### # 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 @@ -11,6 +12,11 @@ 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 ####################################### diff --git a/README.md b/README.md index 9a2e838..f28b5d1 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..d65296a --- /dev/null +++ b/action.yml @@ -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 }} diff --git a/docker-compose.yml b/docker-compose.yml index e0bd6ee..7e8ed92 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,6 +7,7 @@ services: target: DEV volumes: - .:/app/ + - ~/.gitconfig:/root/.gitconfig:ro docs: build: context: . diff --git a/src/Dockerfile b/src/Dockerfile new file mode 100644 index 0000000..162bc47 --- /dev/null +++ b/src/Dockerfile @@ -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 " + +# 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"] diff --git a/src/entrypoint.sh b/src/entrypoint.sh new file mode 100755 index 0000000..8869014 --- /dev/null +++ b/src/entrypoint.sh @@ -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 "github-action@actions-template-sync.noreply.github.com@" +git config --global user.name "actions-template-sync" + +source sync_template.sh diff --git a/src/sync_template.sh b/src/sync_template.sh new file mode 100755 index 0000000..aab3ede --- /dev/null +++ b/src/sync_template.sh @@ -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