Skip to content

Commit

Permalink
Add release workflow (#42)
Browse files Browse the repository at this point in the history
* add new release workflow

* fix endbug/add-and-commit version

* remove some ci actions temporarily

* update readme
  • Loading branch information
joaquimcavalcanti committed Apr 20, 2023
1 parent 37b45bb commit 9360b38
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 22 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@ jobs:
cache: 'npm'
- name: Install
run: npm ci
- name: Format check
run: npm run format:check
- name: Lint
run: npm run lint
- name: Build
run: npm run build
- name: Test
run: npm test --coverage
- name: Commit build
if: github.ref == 'refs/heads/master'
uses: endbug/add-and-commit@v4
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/release-next.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Release Next

on:
workflow_dispatch:
inputs:
branch:
description: 'The source branch to build. Default main.'
default: main
required: true
releaseBranch:
description: 'The release branch to commit to. Default next.'
default: next
required: true

jobs:
release:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.inputs.branch }}
- uses: actions/setup-node@v2
with:
node-version: 16
cache: npm
- name: Install
run: npm install --prefer-offline
- name: Lint
run: npm run lint
- name: Build
run: npm run build
- name: Remove dev dependencies
run: npm install --omit dev --prefer-offline
- name: Commit
uses: endbug/add-and-commit@v9
with:
add: 'build node_modules --force'
branch: ${{ github.event.inputs.releaseBranch }}
message: 'Add build output'
pull: 'NO-PULL'
push: 'origin ${{ github.event.inputs.releaseBranch }} --force'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Reinstall dev dependencies
run: npm install --prefer-offline
49 changes: 49 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Release

on:
workflow_dispatch:
inputs:
tag:
description: 'The version tag of the release. This should match version in package.json and start with `v`. For example: `v2.0.0`'
required: true
releaseBranch:
description: 'The release branch to commit to. Default v2.'
default: v2
required: true

jobs:
release:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
cache: npm
- name: Install
run: npm install --prefer-offline
- name: Lint
run: npm run lint
- name: Build
run: npm run build
- name: Remove dev dependencies
run: npm install --omit dev --prefer-offline
- name: Commit
uses: endbug/add-and-commit@v9
with:
add: 'build node_modules --force'
branch: ${{ github.event.inputs.releaseBranch }}
message: 'Add build output'
pull: 'NO-PULL'
push: 'origin ${{ github.event.inputs.releaseBranch }} --force'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Tag
uses: ncipollo/release-action@v1
with:
body: 'TODO: Add CHANGELOG entry'
tag: ${{ github.event.inputs.tag }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Reinstall dev dependencies
run: npm install --prefer-offline
Empty file modified .husky/pre-commit
100644 → 100755
Empty file.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,15 @@ jobs:
| bodyURLRegexFlags | | The flags applied to the body regular expression when searching for a URL reference | gim |
| exemptUsers | | Comma separated string of usernames that will be exempt from all checks. Most useful for bot/automated PRs (example "octocat,dependabot") | |
| quiet | | If `true`, don't comment when a PR title is updated | true |

## Releasing

### Publishing a release

To publish a release use the [Release](https://github.com/neofinancial/ticket-check-action/actions/workflows/release.yml) workflow. When you run the workflow it will ask you for a version tag like `v2.0.0`. This should be the full version number of the new release. It will also ask you for a major version number like `v2`. This allows you to reference the release as either `@v2` of `@v2.0.0`. You can also reference the hash of the release for additional security.

After the workflow runs a draft release will be created on GitHub. Edit the release and copy the CHANGELOG entries into the description. Then publish the release, including publishing to the GitHub Marketplace.

### Creating a preview Release

To create a preview release use the [Release Next](https://github.com/neofinancial/ticket-check-action/actions/workflows/release-next.yml) workflow. When you run the workflow it will ask you for the name of the branch to build. This should be the feature branch that you want to test. The release will be published to the `next` branch and you can use `neofinancial/ticket-check-action@next` in your workflows to test the preview release.
33 changes: 15 additions & 18 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function run(): Promise<void> {
const title: string = context?.payload?.pull_request?.title;
const titleRegexBase = getInput('titleRegex', { required: true });
const titleRegexFlags = getInput('titleRegexFlags', {
required: true
required: true,
});
const ticketLink = getInput('ticketLink', { required: false });
const titleRegex = new RegExp(titleRegexBase, titleRegexFlags);
Expand All @@ -49,7 +49,7 @@ async function run(): Promise<void> {
// Exempt Users
const exemptUsers = getInput('exemptUsers', { required: false })
.split(',')
.map(user => user.trim());
.map((user) => user.trim());

const linkTicket = async (matchArray: RegExpMatchArray): Promise<void> => {
debug('match array for linkTicket', JSON.stringify(matchArray));
Expand Down Expand Up @@ -78,7 +78,7 @@ async function run(): Promise<void> {
const currentReviews = await client.pulls.listReviews({
owner,
repo,
pull_number: number
pull_number: number,
});

debug('current reviews', JSON.stringify(currentReviews));
Expand All @@ -97,7 +97,7 @@ async function run(): Promise<void> {
repo,
pull_number: number,
body: `See the ticket for this pull request: ${linkToTicket}`,
event: 'COMMENT'
event: 'COMMENT',
});
};

Expand All @@ -109,7 +109,7 @@ async function run(): Promise<void> {
const branch: string = context.payload.pull_request?.head.ref;
const branchRegexBase = getInput('branchRegex', { required: true });
const branchRegexFlags = getInput('branchRegexFlags', {
required: true
required: true,
});
const branchRegex = new RegExp(branchRegexBase, branchRegexFlags);
const branchCheck = branchRegex.exec(branch);
Expand Down Expand Up @@ -148,17 +148,16 @@ async function run(): Promise<void> {
owner,
repo,
pull_number: number,
title: newTitle.replace('%title%', title)
title: newTitle.replace('%title%', title),
});

if (!quiet) {
client.pulls.createReview({
owner,
repo,
pull_number: number,
body:
"Hey! I noticed that your PR contained a reference to the ticket in the branch name but not in the title. I went ahead and updated that for you. Hope you don't mind! ☺️",
event: 'COMMENT'
body: "Hey! I noticed that your PR contained a reference to the ticket in the branch name but not in the title. I went ahead and updated that for you. Hope you don't mind! ☺️",
event: 'COMMENT',
});
}

Expand Down Expand Up @@ -232,17 +231,16 @@ async function run(): Promise<void> {
owner,
repo,
pull_number: number,
title: newTitle.replace('%title%', title)
title: newTitle.replace('%title%', title),
});

if (!quiet) {
client.pulls.createReview({
owner,
repo,
pull_number: number,
body:
"Hey! I noticed that your PR contained a reference to the ticket in the body but not in the title. I went ahead and updated that for you. Hope you don't mind! ☺️",
event: 'COMMENT'
body: "Hey! I noticed that your PR contained a reference to the ticket in the body but not in the title. I went ahead and updated that for you. Hope you don't mind! ☺️",
event: 'COMMENT',
});
}

Expand Down Expand Up @@ -272,7 +270,7 @@ async function run(): Promise<void> {
}

const bodyURLRegexFlags = getInput('bodyURLRegexFlags', {
required: true
required: true,
});
const bodyURLRegex = new RegExp(bodyURLRegexBase, bodyURLRegexFlags);
const bodyURLCheck = bodyURLRegex.exec(body);
Expand Down Expand Up @@ -311,17 +309,16 @@ async function run(): Promise<void> {
owner,
repo,
pull_number: number,
title: newTitle.replace('%title%', title)
title: newTitle.replace('%title%', title),
});

if (!quiet) {
client.pulls.createReview({
owner,
repo,
pull_number: number,
body:
"Hey! I noticed that your PR contained a reference to the ticket URL in the body but not in the title. I went ahead and updated that for you. Hope you don't mind! ☺️",
event: 'COMMENT'
body: "Hey! I noticed that your PR contained a reference to the ticket URL in the body but not in the title. I went ahead and updated that for you. Hope you don't mind! ☺️",
event: 'COMMENT',
});
}
}
Expand Down

0 comments on commit 9360b38

Please sign in to comment.