Skip to content

Commit

Permalink
feat: make template-oss postinstall commit a breaking change for majors
Browse files Browse the repository at this point in the history
When we ship `engines` changes we will release a semver major update
to template-oss, and the resulting dependabot PRs will get a `feat!`
commit to indicate that they will all need major releases as well.

This also updates the workflow to attempt to commit a subset of the
applied changes, without the workflows. The workflow will still fail, if
any changes were not committed but this allows us to have the proper
conventional commit message in the git history that we can amend when
fixing these PRs manually.
  • Loading branch information
lukekarrys committed Sep 1, 2022
1 parent e851661 commit 63780f2
Show file tree
Hide file tree
Showing 3 changed files with 229 additions and 21 deletions.
62 changes: 57 additions & 5 deletions .github/workflows/post-dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,67 @@ jobs:
- run: npm i --ignore-scripts --no-audit --no-fund
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.1.1
uses: dependabot/fetch-metadata@v1
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Apply @npmcli/template-oss changes and lint

# A new version of template-oss will always have changes
# so we dont need to check the git status here
- name: Apply changes
if: contains(steps.metadata.outputs.dependency-names, '@npmcli/template-oss')
id: apply
run: |
npx --offline template-oss-apply --force
echo "::set-output name=changes::true"
# If we are updating to a semver major version, then we should treat the result
# of template-oss-apply as a breaking change
- name: Set commit prefix
id: commit
if: steps.apply.outputs.changes
run: |
# TODO: we should have a way of setting the BREAKING CHANGE commit footer
# so we have a nice changelog message. It will usually just be the engines field being updated.
if [[ "${{ steps.dependabot-metadata.outputs.update-type }}" == "version-update:semver-major" ]]; then
echo "::set-output name=prefix::feat!"
else
echo "::set-output name=prefix::chore"
fi
# This step will fail if template-oss has made any workflow updates. It is impossible
# for a workflow to update other workflows. In this case it does fail, we continue
# and try to apply only a portion of the changes
- name: Commit and push all changes
if: steps.apply.outputs.changes
id: push
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npm run template-oss-apply
git commit -am "chore: postinstall for dependabot template-oss PR"
git commit -am "${{ steps.commit.outputs.prefix }}: postinstall for dependabot template-oss PR"
git push
npm run lint
# If the previous step failed, then reset the commit and remove any workflow changes
# and attempt to commit and push again. This is helpful because we will have a commit
# with the correct prefix that we can then --amend with @npmcli/stafftools later.
- name: Commit and push all changes except workflows
if: steps.apply.outputs.changes && steps.push-all.outcome == 'failure'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git reset HEAD~
git clean -fd .github/workflows/
git commit -am "${{ steps.commit.outputs.prefix }}: postinstall for dependabot template-oss PR"
git push
# Check if all the necessary template-oss changes were applied. Since we continued
# on errors in one of the previous steps, this check will fail if our follow up
# only applied a portion of the changes and we need to followup manually.
#
# Note that this used to run `lint` and `postlint` but that will fail this action
# if we've also shipped any linting changes separate from template-oss. We do
# linting in another action, so we want to fail this one only if there are
# template-oss changes that could not be applied.
- name: Check for changes
if: steps.apply.outputs.changes
run: npx --offline template-oss-check
64 changes: 58 additions & 6 deletions lib/content/post-dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,67 @@ jobs:
{{> setupDeps}}
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.1.1
uses: dependabot/fetch-metadata@v1
with:
github-token: "$\{{ secrets.GITHUB_TOKEN }}"
- name: Apply {{__NAME__}} changes and lint
github-token: "$\{{ secrets.GITHUB_TOKEN }}"

# A new version of template-oss will always have changes
# so we dont need to check the git status here
- name: Apply changes
if: contains(steps.metadata.outputs.dependency-names, '{{__NAME__}}')
id: apply
run: |
npx --offline template-oss-apply --force
echo "::set-output name=changes::true"
# If we are updating to a semver major version, then we should treat the result
# of template-oss-apply as a breaking change
- name: Set commit prefix
id: commit
if: steps.apply.outputs.changes
run: |
# TODO: we should have a way of setting the BREAKING CHANGE commit footer
# so we have a nice changelog message. It will usually just be the engines field being updated.
if [[ "$\{{ steps.dependabot-metadata.outputs.update-type }}" == "version-update:semver-major" ]]; then
echo "::set-output name=prefix::feat!"
else
echo "::set-output name=prefix::chore"
fi
# This step will fail if template-oss has made any workflow updates. It is impossible
# for a workflow to update other workflows. In this case it does fail, we continue
# and try to apply only a portion of the changes
- name: Commit and push all changes
if: steps.apply.outputs.changes
id: push
continue-on-error: true
env:
GITHUB_TOKEN: $\{{ secrets.GITHUB_TOKEN }}
run: |
npm run template-oss-apply
git commit -am "chore: postinstall for dependabot template-oss PR"
git commit -am "$\{{ steps.commit.outputs.prefix }}: postinstall for dependabot template-oss PR"
git push
npm run lint
# If the previous step failed, then reset the commit and remove any workflow changes
# and attempt to commit and push again. This is helpful because we will have a commit
# with the correct prefix that we can then --amend with @npmcli/stafftools later.
- name: Commit and push all changes except workflows
if: steps.apply.outputs.changes && steps.push-all.outcome == 'failure'
env:
GITHUB_TOKEN: $\{{ secrets.GITHUB_TOKEN }}
run: |
git reset HEAD~
git clean -fd .github/workflows/
git commit -am "$\{{ steps.commit.outputs.prefix }}: postinstall for dependabot template-oss PR"
git push
# Check if all the necessary template-oss changes were applied. Since we continued
# on errors in one of the previous steps, this check will fail if our follow up
# only applied a portion of the changes and we need to followup manually.
#
# Note that this used to run `lint` and `postlint` but that will fail this action
# if we've also shipped any linting changes separate from template-oss. We do
# linting in another action, so we want to fail this one only if there are
# template-oss changes that could not be applied.
- name: Check for changes
if: steps.apply.outputs.changes
run: npx --offline template-oss-check
124 changes: 114 additions & 10 deletions tap-snapshots/test/apply/full-content.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -364,18 +364,70 @@ jobs:
- run: npm i --ignore-scripts --no-audit --no-fund
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.1.1
uses: dependabot/fetch-metadata@v1
with:
github-token: "\${{ secrets.GITHUB_TOKEN }}"
- name: Apply @npmcli/template-oss changes and lint
# A new version of template-oss will always have changes
# so we dont need to check the git status here
- name: Apply changes
if: contains(steps.metadata.outputs.dependency-names, '@npmcli/template-oss')
id: apply
run: |
npx --offline template-oss-apply --force
echo "::set-output name=changes::true"
# If we are updating to a semver major version, then we should treat the result
# of template-oss-apply as a breaking change
- name: Set commit prefix
id: commit
if: steps.apply.outputs.changes
run: |
# TODO: we should have a way of setting the BREAKING CHANGE commit footer
# so we have a nice changelog message. It will usually just be the engines field being updated.
if [[ "\${{ steps.dependabot-metadata.outputs.update-type }}" == "version-update:semver-major" ]]; then
echo "::set-output name=prefix::feat!"
else
echo "::set-output name=prefix::chore"
fi
# This step will fail if template-oss has made any workflow updates. It is impossible
# for a workflow to update other workflows. In this case it does fail, we continue
# and try to apply only a portion of the changes
- name: Commit and push all changes
if: steps.apply.outputs.changes
id: push
continue-on-error: true
env:
GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
run: |
npm run template-oss-apply
git commit -am "chore: postinstall for dependabot template-oss PR"
git commit -am "\${{ steps.commit.outputs.prefix }}: postinstall for dependabot template-oss PR"
git push
npm run lint
# If the previous step failed, then reset the commit and remove any workflow changes
# and attempt to commit and push again. This is helpful because we will have a commit
# with the correct prefix that we can then --amend with @npmcli/stafftools later.
- name: Commit and push all changes except workflows
if: steps.apply.outputs.changes && steps.push-all.outcome == 'failure'
env:
GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
run: |
git reset HEAD~
git clean -fd .github/workflows/
git commit -am "\${{ steps.commit.outputs.prefix }}: postinstall for dependabot template-oss PR"
git push
# Check if all the necessary template-oss changes were applied. Since we continued
# on errors in one of the previous steps, this check will fail if our follow up
# only applied a portion of the changes and we need to followup manually.
#
# Note that this used to run \`lint\` and \`postlint\` but that will fail this action
# if we've also shipped any linting changes separate from template-oss. We do
# linting in another action, so we want to fail this one only if there are
# template-oss changes that could not be applied.
- name: Check for changes
if: steps.apply.outputs.changes
run: npx --offline template-oss-check
.github/workflows/pull-request.yml
========================================
Expand Down Expand Up @@ -1292,18 +1344,70 @@ jobs:
- run: npm i --ignore-scripts --no-audit --no-fund
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.1.1
uses: dependabot/fetch-metadata@v1
with:
github-token: "\${{ secrets.GITHUB_TOKEN }}"
- name: Apply @npmcli/template-oss changes and lint
# A new version of template-oss will always have changes
# so we dont need to check the git status here
- name: Apply changes
if: contains(steps.metadata.outputs.dependency-names, '@npmcli/template-oss')
id: apply
run: |
npx --offline template-oss-apply --force
echo "::set-output name=changes::true"
# If we are updating to a semver major version, then we should treat the result
# of template-oss-apply as a breaking change
- name: Set commit prefix
id: commit
if: steps.apply.outputs.changes
run: |
# TODO: we should have a way of setting the BREAKING CHANGE commit footer
# so we have a nice changelog message. It will usually just be the engines field being updated.
if [[ "\${{ steps.dependabot-metadata.outputs.update-type }}" == "version-update:semver-major" ]]; then
echo "::set-output name=prefix::feat!"
else
echo "::set-output name=prefix::chore"
fi
# This step will fail if template-oss has made any workflow updates. It is impossible
# for a workflow to update other workflows. In this case it does fail, we continue
# and try to apply only a portion of the changes
- name: Commit and push all changes
if: steps.apply.outputs.changes
id: push
continue-on-error: true
env:
GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
run: |
npm run template-oss-apply
git commit -am "chore: postinstall for dependabot template-oss PR"
git commit -am "\${{ steps.commit.outputs.prefix }}: postinstall for dependabot template-oss PR"
git push
npm run lint
# If the previous step failed, then reset the commit and remove any workflow changes
# and attempt to commit and push again. This is helpful because we will have a commit
# with the correct prefix that we can then --amend with @npmcli/stafftools later.
- name: Commit and push all changes except workflows
if: steps.apply.outputs.changes && steps.push-all.outcome == 'failure'
env:
GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
run: |
git reset HEAD~
git clean -fd .github/workflows/
git commit -am "\${{ steps.commit.outputs.prefix }}: postinstall for dependabot template-oss PR"
git push
# Check if all the necessary template-oss changes were applied. Since we continued
# on errors in one of the previous steps, this check will fail if our follow up
# only applied a portion of the changes and we need to followup manually.
#
# Note that this used to run \`lint\` and \`postlint\` but that will fail this action
# if we've also shipped any linting changes separate from template-oss. We do
# linting in another action, so we want to fail this one only if there are
# template-oss changes that could not be applied.
- name: Check for changes
if: steps.apply.outputs.changes
run: npx --offline template-oss-check
.github/workflows/pull-request.yml
========================================
Expand Down

0 comments on commit 63780f2

Please sign in to comment.