From 6988b5158316a8ed01815acfd5a0d45f8dfa5c7e Mon Sep 17 00:00:00 2001 From: GBA bot Date: Wed, 24 Nov 2021 22:44:11 +0000 Subject: [PATCH] Update template repo on release of agb --- .github/scripts/update-template-repo.sh | 30 +++++++++++++++++++++++++ .github/workflows/publish-agb.yml | 8 ++++++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100755 .github/scripts/update-template-repo.sh diff --git a/.github/scripts/update-template-repo.sh b/.github/scripts/update-template-repo.sh new file mode 100755 index 00000000..d2bb3b27 --- /dev/null +++ b/.github/scripts/update-template-repo.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +set -e # Fail if any command fails +set -x # print every command before it runs + +# Updates the template repository to the content of the template directory +# Requires environment variable +# - GITHUB_USERNAME = a user who has push access to the template repository +# - API_TOKEN_GITHUB = an API token for the user + +CLONE_DIR=$(mktemp -d) + +# Setup git +git config --global user.email "gw@ilym.me" # TODO: Have an email address for agb bot +git config --global user.name "GBA bot" +git clone --single-branch --branch master "https://$GITHUB_USERNAME:$API_TOKEN_GITHUB@github.com/agbrs/template.git" "$CLONE_DIR" + +# Copy the .git directory to a different place so we can ensure that only the relevant template stuff stays +TEMP_DIR=$(mktemp -d) +mv "$CLONE_DIR/.git" "$TEMP_DIR/.git" + +cp -rva template/. "$TEMP_DIR" + +# git describe will give a unique, friendly name for the current commit to make it easier to track where this came from +VERSION=$(git describe) +COMMIT_MESSAGE="Update to $VERSION" + +git -C "$TEMP_DIR" add . +git -C "$TEMP_DIR" commit -m "$COMMIT_MESSAGE" +git -C "$TEMP_DIR" push origin HEAD \ No newline at end of file diff --git a/.github/workflows/publish-agb.yml b/.github/workflows/publish-agb.yml index 92563c8d..f2a2efbc 100644 --- a/.github/workflows/publish-agb.yml +++ b/.github/workflows/publish-agb.yml @@ -18,4 +18,10 @@ jobs: run: cargo login ${{ secrets.CRATE_API }} - name: Publish agb run: cargo publish - working-directory: ./agb \ No newline at end of file + working-directory: ./agb + + - name: Update template repo + env: + GITHUB_USERNAME: gwilymk + API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }} + run: bash .github/scripts/update-template-repo.sh \ No newline at end of file