Last active
October 30, 2019 23:44
-
-
Save swinton/2ba2dd19eb0507554c4d446f6568b4bf to your computer and use it in GitHub Desktop.
Sync release branch with master on every push to master, and include productionized node_modules folder on release
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Prepare Release Branch | |
on: | |
push: | |
branches: # array of glob patterns matching against refs/heads. Optional; defaults to all | |
- master # triggers on pushes that contain changes in master | |
jobs: | |
prepare-release-branch: | |
name: Prepare Release Branch | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/[email protected] | |
- run: | | |
# Add origin as remote | |
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git | |
# Hard-code user config | |
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" | |
git config user.name "${GITHUB_REPOSITORY}[bot]" | |
# Make sure HEAD is not detached | |
git checkout -b master | |
# Fetch origin | |
git fetch origin | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Sync with release branch | |
run: | | |
if [ -f .git/refs/remotes/origin/release ]; then | |
# refs/heads/release exists at origin | |
git checkout release | |
# Merge in latest master | |
git merge -m "${COMMIT_MSG}" master | |
else | |
# refs/heads/release does not exist at origin | |
git checkout -b release | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
COMMIT_MSG: | | |
sync: master | |
skip-checks: true | |
# Install production dependencies | |
- run: npm i --only=production | |
- run: | | |
git add --force package-lock.json node_modules | |
# Look for staged changes | |
if [[ $(git diff --cached --stat) != '' ]]; then | |
# Changes have been staged, commit them | |
git commit -m "${COMMIT_MSG}" | |
fi | |
# Push our changes back to the release branch | |
git push origin release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
COMMIT_MSG: | | |
build: dist | |
skip-checks: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment