diff --git a/.github/workflows/push-to-stable.yml b/.github/workflows/push-to-stable.yml new file mode 100644 index 0000000..8c1ea0b --- /dev/null +++ b/.github/workflows/push-to-stable.yml @@ -0,0 +1,63 @@ +# @author jphaupt +name: Push changes to a public repository + +on: + push: + branches: + - stable # branch on private that triggers action + +# edit these environment variables if you wish to use in a new project +# note this depends on a separate workflow called build_and_test to exist +# (this job does not run unless build_and_test is successful) +env: + BOT_TOKEN: ${{ secrets.PRIVATE_TO_PUBLIC_PAT }} # PAT for jph-bot + TARGET_REPO: e-cojl + TARGET_BRANCH: main + SOURCE_REPO: e-cojl-devel + SOURCE_BRANCH: stable + +jobs: + push-changes: + runs-on: ubuntu-latest + steps: + - name: checkout code + uses: actions/checkout@v2 + with: + ref: stable # unfortunately, cannot use env here, must change manually as well + fetch-depth: 0 + + - name: clone $SOURCE_BRANCH repo + run: | + git clone https://fkfest:$BOT_TOKEN@github.com/fkfest/$TARGET_REPO.git + cd $TARGET_REPO + git checkout -b auto/from-devel-repo + git config user.name "actions-user" + git config user.email "actions@github.com" + - name: pull changes into local copy of public repo from private repo + run: | + cd $TARGET_REPO + git remote add source https://fkfest:$BOT_TOKEN@github.com/fkfest/$SOURCE_REPO + git fetch source $SOURCE_BRANCH + - name: merge changes in public repo + run: | + cd $TARGET_REPO + git merge source/$SOURCE_BRANCH --no-edit + - name: publish new branch + run: | + cd $TARGET_REPO + git push -u origin auto/from-devel-repo + - name: Create Pull Request + run: | + cd $TARGET_REPO + PR_TITLE="Merge changes from development repository" + PR_BODY="This pull request merges changes from the private development repository and was automatically generated by GitHub Actions." + PR_HEAD="auto/from-devel-repo" # branch with changes + PR_BASE="$TARGET_BRANCH" + PR_API_URL=$(curl --silent --request POST --url https://api.github.com/repos/fkfest/$TARGET_REPO/pulls \ + --header "authorization: Bearer $BOT_TOKEN" \ + --header "content-type: application/json" \ + --data "{\"title\":\"$PR_TITLE\",\"body\":\"$PR_BODY\",\"head\":\"$PR_HEAD\",\"base\":\"$PR_BASE\"}" \ + --write-out '%{url_effective}' \ + --output /dev/null) + PR_NUMBER=$(echo $PR_API_URL | cut -d / -f 8) + echo "Pull Request #$PR_NUMBER created."