Skip to content

Commit

Permalink
Update GitHub workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubmazanec committed Oct 11, 2023
1 parent a25a3b1 commit f39cf15
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 51 deletions.
Binary file modified .carson/workspace.snapshot
Binary file not shown.
5 changes: 5 additions & 0 deletions .changeset/brown-bananas-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@jakubmazanec/carson-templates': minor
---

Adds support for Renovate bot to the GitHub workflows in `workspace` template.
13 changes: 11 additions & 2 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ on:
- development

jobs:
pull_request_check:
check_pull_request:
name: Check pull request
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v3
with:
token: ${{secrets.GITHUB_TOKEN}}
token: ${{secrets.PAT}}
fetch-depth: 0

- name: Configure git
run: |
git config user.email "[email protected]"
git config user.name "Bot"
- uses: actions/setup-node@v3
with:
node-version: 16
Expand All @@ -23,6 +29,7 @@ jobs:
run: npm ci

- name: Check for changes
if: "github.actor != 'renovate[bot]'"
run: |
git config core.filemode false
git_status=$(git status --porcelain)
Expand All @@ -40,6 +47,7 @@ jobs:
run: npm test

- name: Check for changes
if: "github.actor != 'renovate[bot]'"
run: |
git config core.filemode false
git_status=$(git status --porcelain)
Expand All @@ -54,4 +62,5 @@ jobs:
git config --unset core.filemode
- name: Check for changesets
if: "github.actor != 'renovate[bot]'"
run: npx changeset status --since=origin/development
22 changes: 12 additions & 10 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Release
on: [push, workflow_dispatch]

jobs:
main_branch_release:
release_main_branch:
name: Main branch release
runs-on: ubuntu-latest
timeout-minutes: 15
Expand Down Expand Up @@ -39,7 +39,7 @@ jobs:
if [[ -n $git_status ]]; then
echo "You have uncommitted changes!"
git status --porcelain
git diff
git config --unset core.filemode
exit 1
fi
Expand All @@ -56,7 +56,7 @@ jobs:
if [[ -n $git_status ]]; then
echo "You have uncommitted changes!"
git status --porcelain
git diff
git config --unset core.filemode
exit 1
fi
Expand Down Expand Up @@ -127,7 +127,7 @@ jobs:
git merge main --no-verify
git push -u origin development --no-verify
development_branch_release:
release_development_branch:
name: Development branch release
runs-on: ubuntu-latest
timeout-minutes: 15
Expand Down Expand Up @@ -163,7 +163,7 @@ jobs:
if [[ -n $git_status ]]; then
echo "You have uncommitted changes!"
git status --porcelain
git diff
git config --unset core.filemode
exit 1
fi
Expand All @@ -180,7 +180,7 @@ jobs:
if [[ -n $git_status ]]; then
echo "You have uncommitted changes!"
git status --porcelain
git diff
git config --unset core.filemode
exit 1
fi
Expand Down Expand Up @@ -220,11 +220,13 @@ jobs:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

feature_branch_release:
release_feature_branch:
name: Feature branch release
runs-on: ubuntu-latest
timeout-minutes: 15
if: "github.ref_name != 'main' && github.ref_name != 'development'"
if:
"github.ref_name != 'main' && github.ref_name != 'development' && github.actor !=
'renovate[bot]'"
steps:
- name: Cancel previous runs
uses: styfle/[email protected]
Expand Down Expand Up @@ -256,7 +258,7 @@ jobs:
if [[ -n $git_status ]]; then
echo "You have uncommitted changes!"
git status --porcelain
git diff
git config --unset core.filemode
exit 1
fi
Expand All @@ -273,7 +275,7 @@ jobs:
if [[ -n $git_status ]]; then
echo "You have uncommitted changes!"
git status --porcelain
git diff
git config --unset core.filemode
exit 1
fi
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
name: Generate changeset
name: Update pull request

on:
workflow_dispatch:
pull_request_target:
paths:
- '.github/workflows/renovate.yaml'
- '**/package.json'
- '**/package-lock.json'
branches: [development]

jobs:
generate-changeset:
name: Generate changeset
update_pull_request:
name: Update pull request
if: ${{ github.actor == 'renovate[bot]' && contains(github.head_ref, 'renovate/') }}
runs-on: ubuntu-latest
timeout-minutes: 15
if: github.actor == 'renovate[bot]'
steps:
- name: Cancel previous runs
uses: styfle/[email protected]
with:
access_token: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
Expand All @@ -31,8 +22,16 @@ jobs:
git config user.email "[email protected]"
git config user.name "Bot"
- uses: actions/setup-node@v3
with:
node-version: 16

- name: Install packages
run: npm ci

- name: Generate changeset
uses: actions/github-script@v6
if: ${{ github.actor == 'renovate[bot]' }}
with:
script: |
let { promises: fs } = require('fs');
Expand All @@ -56,9 +55,11 @@ jobs:
for (let [packageName, bump] of packageBumps) {
message =
message + `Dependency \`${packageName}\` updated to \`${bump}\`.\n`;
message + `Dependency \`${packageName}\` updated to version \`${bump}\`.\n`;
}
message = message.replace('\n', ' ');
let header = packages
.map((packageName) => `'${packageName}': patch`)
.join('\n');
Expand Down Expand Up @@ -86,14 +87,6 @@ jobs:
return bumps;
}
let branch = await exec.getExecOutput('git branch --show-current');
if (!branch.stdout.startsWith('renovate/')) {
console.log('Not a renovate branch, skipping...');
return;
}
let diffOutput = await exec.getExecOutput('git diff --name-only HEAD~1');
let diffFiles = diffOutput.stdout.split('\n');
Expand All @@ -111,6 +104,8 @@ jobs:
if (!packageNames.length) {
console.log('No package.json changes to published packages, skipping...');
await exec.exec('npx', ['changeset', '--empty']);
return;
}
Expand All @@ -121,6 +116,15 @@ jobs:
let packageBumps = await getBumps(files);
await createChangeset(fileName, packageBumps, packageNames);
await exec.exec('git', ['add', fileName]);
await exec.exec('git commit -C HEAD --amend --no-edit');
await exec.exec('git push --force');
- name: Update Carson
if: ${{ github.actor == 'renovate[bot]' }}
run: |
npm install
- name: Commit and push changes
if: ${{ github.actor == 'renovate[bot]' }}
run: |
git add . --all
git commit -C HEAD --amend --no-edit
git push --force
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ on:
- development

jobs:
pull_request_check:
check_pull_request:
name: Check pull request
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v3
with:
token: ${{secrets.GITHUB_TOKEN}}
token: ${{secrets.PAT}}
fetch-depth: 0

- name: Configure git
run: |
git config user.email "[email protected]"
git config user.name "Bot"

- uses: actions/setup-node@v3
with:
node-version: 16
Expand All @@ -27,6 +33,7 @@ jobs:
run: npm ci

- name: Check for changes
if: "github.actor != 'renovate[bot]'"
run: |
git config core.filemode false
git_status=$(git status --porcelain)
Expand All @@ -44,6 +51,7 @@ jobs:
run: npm test

- name: Check for changes
if: "github.actor != 'renovate[bot]'"
run: |
git config core.filemode false
git_status=$(git status --porcelain)
Expand All @@ -58,4 +66,5 @@ jobs:
git config --unset core.filemode

- name: Check for changesets
run: npx changeset status --since=origin/development
if: "github.actor != 'renovate[bot]'"
run: npx changeset status --since=origin/<%- getDevelopmentBranch(workspace) %>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name: Release
on: [push, workflow_dispatch]

jobs:
main_branch_release:
release_main_branch:
name: Main branch release
runs-on: ubuntu-latest
timeout-minutes: 15
Expand Down Expand Up @@ -43,7 +43,7 @@ jobs:

if [[ -n $git_status ]]; then
echo "You have uncommitted changes!"
git status --porcelain
git diff
git config --unset core.filemode
exit 1
fi
Expand All @@ -60,7 +60,7 @@ jobs:

if [[ -n $git_status ]]; then
echo "You have uncommitted changes!"
git status --porcelain
git diff
git config --unset core.filemode
exit 1
fi
Expand Down Expand Up @@ -131,7 +131,7 @@ jobs:
git merge <%- getMainBranch(workspace) %> --no-verify
git push -u origin <%- getDevelopmentBranch(workspace) %> --no-verify

development_branch_release:
release_development_branch:
name: Development branch release
runs-on: ubuntu-latest
timeout-minutes: 15
Expand Down Expand Up @@ -167,7 +167,7 @@ jobs:

if [[ -n $git_status ]]; then
echo "You have uncommitted changes!"
git status --porcelain
git diff
git config --unset core.filemode
exit 1
fi
Expand All @@ -184,7 +184,7 @@ jobs:

if [[ -n $git_status ]]; then
echo "You have uncommitted changes!"
git status --porcelain
git diff
git config --unset core.filemode
exit 1
fi
Expand Down Expand Up @@ -224,11 +224,11 @@ jobs:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

feature_branch_release:
release_feature_branch:
name: Feature branch release
runs-on: ubuntu-latest
timeout-minutes: 15
if: "github.ref_name != '<%- getMainBranch(workspace) %>' && github.ref_name != '<%- getDevelopmentBranch(workspace) %>'"
if: "github.ref_name != '<%- getMainBranch(workspace) %>' && github.ref_name != '<%- getDevelopmentBranch(workspace) %>' && github.actor != 'renovate[bot]'"
steps:
- name: Cancel previous runs
uses: styfle/[email protected]
Expand Down Expand Up @@ -260,7 +260,7 @@ jobs:

if [[ -n $git_status ]]; then
echo "You have uncommitted changes!"
git status --porcelain
git diff
git config --unset core.filemode
exit 1
fi
Expand All @@ -277,7 +277,7 @@ jobs:

if [[ -n $git_status ]]; then
echo "You have uncommitted changes!"
git status --porcelain
git diff
git config --unset core.filemode
exit 1
fi
Expand Down
Loading

0 comments on commit f39cf15

Please sign in to comment.