Skip to content

Commit

Permalink
chore(repo): move pull, push release operations into workflow. ignore…
Browse files Browse the repository at this point in the history
… release commits
  • Loading branch information
shellscape committed Jul 16, 2021
1 parent eaf4f88 commit 6a32b4d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 30 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:

jobs:
publish:
# let's ignore release commits, otherwise it'll try to run twice
if: !startsWith(github.event.head_commit.message , 'chore(release):')

runs-on: ubuntu-latest

name: release
Expand Down Expand Up @@ -67,3 +70,12 @@ jobs:
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Push Release and Cleanup
run: |
git checkout .npmrc
git add . && git commit --amend --no-edit
git pull origin master --no-edit
git rebase
git push origin HEAD:master
git push origin HEAD:master -- tags
30 changes: 0 additions & 30 deletions scripts/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const parserOptions = {
const reBreaking = new RegExp(`(${parserOptions.noteKeywords.join(')|(')})`);
const dryRun = process.argv.includes('--dry');
const noPublish = process.argv.includes('--no-publish');
const noPush = process.argv.includes('--no-push');
const noTag = process.argv.includes('--no-tag');

type Commit = parser.Commit<string | number | symbol>;
Expand Down Expand Up @@ -121,34 +120,6 @@ const publish = async (cwd: string) => {
await execa('npm', ['publish', '--no-git-checks'], { cwd, stdio: 'inherit' });
};

const pull = async (main: string) => {
log(chalk`{blue Pulling Latest Changes from Remote and Rebasing}`);

await execa('git', ['checkout', '.npmrc']);
await execa('git', ['pull', 'origin', main, '--no-edit']);
const { stdout } = await execa('git', ['status']);
console.log({ stdout });
await execa('git', ['rebase']);
};

const push = async () => {
if (dryRun || noPush) {
log(chalk`{yellow Skipping Git Push}`);
return;
}

const { stdout: branches } = await execa('git', ['branch']);
const main = branches.includes('main') ? 'main' : 'master';

await pull(main);

const params = ['push', 'origin', `HEAD:${main}`];

log(chalk`{blue Pushing Release and Tags}`);
await execa('git', params);
await execa('git', [...params, '--tags']);
};

const tag = async (cwd: string, shortName: string, version: string) => {
if (dryRun || noTag) {
log(chalk`{yellow Skipping Git Tag}`);
Expand Down Expand Up @@ -257,7 +228,6 @@ const updatePackage = async (cwd: string, pkg: RepoPackage, version: string) =>
await commitChanges(cwd, shortName, newVersion);
await publish(cwd);
await tag(cwd, shortName, newVersion);
await push();
} catch (e) {
log(e);
process.exit(1);
Expand Down

0 comments on commit 6a32b4d

Please sign in to comment.