Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation #13

Merged
merged 29 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d868fc6
Define our inputs and strip template implementation
simu Oct 31, 2023
06aea58
Implement git tag parsing
simu Nov 1, 2023
0157c28
Implement logic to parse PR labels and bump version
simu Nov 1, 2023
2d18f86
Fix linting errors and disable some linting rules
simu Nov 1, 2023
85bcfd1
Don't lint generated `licenses.txt`
simu Nov 1, 2023
a262b31
Specify `github-token` for the action in the test workflow
simu Nov 1, 2023
656cca8
Add logic to create/update PR comments and implement initial main logic
simu Nov 1, 2023
94ba1b4
Move action test to separate workflow and customize triggers
simu Nov 2, 2023
1d9c462
Introduce `formatCode()` to make comment text generation easier
simu Nov 2, 2023
7c5de5b
Add all discovered labels in comment when multiple bump labels are pr…
simu Nov 2, 2023
05e2e4d
Add tests for src/comment.ts
simu Nov 2, 2023
b116332
Deduplicate test setup for bump-labels tests
simu Nov 2, 2023
273cf33
Add test case for unreachable path in bump-labels
simu Nov 2, 2023
6c13a9b
Implement creating and pushing new tag
simu Nov 2, 2023
7dcc9cb
Implement workflow triggering
simu Nov 2, 2023
60e1c72
Add information message on workflow trigger function
simu Nov 2, 2023
16de293
Make comment contents optional inputs and switch marker to `Auto tagg…
simu Nov 2, 2023
9d7cf28
Move workflow triggering to own file, add tests
simu Nov 3, 2023
b1e62fa
Get PR labels from `github.context` instead of making API call
simu Nov 3, 2023
7c1847d
Fetch tags from GitHub API instead of running `git` locally
simu Nov 3, 2023
8bf9f41
Implement tag creation with API call
simu Nov 3, 2023
a735ed3
Ignore non-semver tags when finding latest tag
simu Nov 3, 2023
8b4a931
Set `github.token` as default for `github-token` input
simu Nov 3, 2023
01b2d8b
Adjust release URL template naming in customizable comment inputs
simu Nov 3, 2023
41c3b74
Add informational output when the action bumps the version
simu Nov 3, 2023
aff3a0f
Add Project Syn boilerplate
simu Nov 3, 2023
c791fdb
Update README
simu Nov 3, 2023
f17c619
Fix markdown linting errors
simu Nov 3, 2023
56e2c3f
Update comment when all bump labels are removed
simu Nov 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
Thank you for your pull request. Please provide a description above and
review the checklist below.

Contributors guide: ./CONTRIBUTING.md
-->

## Checklist

<!--
Remove items that do not apply. For completed items, change [ ] to [x].
-->

- [ ] PR contains a single logical change (to build a better changelog).
- [ ] Update the documentation.
- [ ] Update tests.
- [ ] Categorize the PR by setting a good title and adding one of the labels:
`bug`, `enhancement`, `documentation`, `change`, `breaking`, `dependency`
as they show up in the changelog
- [ ] Link this PR to related issues.

<!--
NOTE: these things are not required to open a PR and can be done afterwards,
while the PR is open.
-->
30 changes: 30 additions & 0 deletions .github/changelog-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{

Check warning on line 1 in .github/changelog-configuration.json

View workflow job for this annotation

GitHub Actions / Lint Code Base

File ignored by default.
"pr_template": "- ${{TITLE}} (#${{NUMBER}})",
"categories": [
{
"title": "## 🚀 Features",
"labels": ["enhancement", "feature"]
},
{
"title": "## 🛠️ Minor Changes",
"labels": ["change"]
},
{
"title": "## 🔎 Breaking Changes",
"labels": ["breaking"]
},
{
"title": "## 🐛 Fixes",
"labels": ["bug", "fix"]
},
{
"title": "## 📄 Documentation",
"labels": ["documentation"]
},
{
"title": "## 🔗 Dependency Updates",
"labels": ["dependency"]
}
],
"template": "${{CATEGORIZED_COUNT}} changes since ${{FROM_TAG}}\n\n${{CHANGELOG}}"
}
5 changes: 3 additions & 2 deletions .github/linters/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ rules:
'@typescript-eslint/func-call-spacing': ['error', 'never'],
'@typescript-eslint/no-array-constructor': 'error',
'@typescript-eslint/no-empty-interface': 'error',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-extraneous-class': 'error',
'@typescript-eslint/no-for-in-array': 'error',
'@typescript-eslint/no-inferrable-types': 'error',
Expand All @@ -79,5 +79,6 @@ rules:
'@typescript-eslint/semi': ['error', 'never'],
'@typescript-eslint/space-before-function-paren': 'off',
'@typescript-eslint/type-annotation-spacing': 'error',
'@typescript-eslint/unbound-method': 'error'
'@typescript-eslint/unbound-method': 'error',
'jest/no-conditional-expect': 'off'
}
7 changes: 7 additions & 0 deletions .github/linters/.markdown-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
MD004:
style: dash

# Line length is pointless since we have a table in the README
MD013:
line_length: 200

# Ordered list item prefix
MD029:
style: one

# allow bare urls
MD034: false
19 changes: 0 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,3 @@ jobs:
- name: Test
id: npm-ci-test
run: npm run ci-test

test-action:
name: GitHub Actions Test
runs-on: ubuntu-latest

steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4

- name: Test Local Action
id: test-action
uses: ./
with:
milliseconds: 1000

- name: Print Output
id: output
run: echo "${{ steps.test-action.outputs.time }}"
4 changes: 1 addition & 3 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ on:
pull_request:
branches:
- main
push:
branches-ignore:
- main

jobs:
lint:
Expand Down Expand Up @@ -42,3 +39,4 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TYPESCRIPT_DEFAULT_STYLE: prettier
VALIDATE_JSCPD: false
FILTER_REGEX_EXCLUDE: '(dist/licenses\.txt|PULL_REQUEST_TEMPLATE.md)'
39 changes: 39 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Release
on:
push:
tags:
- v*
workflow_dispatch:

jobs:
dist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: '0'
- name: Build changelog from PRs with labels
id: build_changelog
uses: mikepenz/release-changelog-builder-action@v4
with:
configuration: '.github/changelog-configuration.json'
# PreReleases still get a changelog, but the next full release gets a diff since the last full release,
# combining possible changelogs of all previous PreReleases in between.
# PreReleases show a partial changelog since last PreRelease.
ignorePreReleases: "${{ !contains(github.ref, '-rc') }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
uses: ncipollo/release-action@v1
with:
body: ${{steps.build_changelog.outputs.changelog}}
prerelease: "${{ contains(github.ref, '-rc') }}"
# Ensure target branch for release is "master"
commit: master
token: ${{ secrets.GITHUB_TOKEN }}
# Create a bare v<major> tag, so that users can use our action with
# @v<major>
- name: Update SemVer tag
uses: rickstaa/action-update-semver@v1
with:
major_version_tag_only: true
27 changes: 27 additions & 0 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Action CI

on:
pull_request:
types:
- synchronize
- labeled
- unlabeled
- closed

jobs:
test-action:
name: GitHub Actions Test
runs-on: ubuntu-latest

steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4

- name: Test Local Action
id: test-action
uses: ./
with:
# Configure the action so it can release itself
trigger: |
Release
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# How to contribute

This code repository is part of Project Syn and the contribution guide at
https://syn.tools/syn/about/contribution_guide.html does apply.

Submit Pull Requests at https://github.com/projectsyn/pr-label-tag-action/pulls.
58 changes: 51 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,22 @@ This action looks for specific labels (by default `bump:major`, `bump:minor`, an
`bump:patch`) on PRs, and creates a new SemVer tag based on the current latest
version of the repository after a PR with one of the labels is merged.

Currently, the action doesn't allow customizing the tag format. It will always
look for SemVer version tags prefixed with `v` and will create such tags.

The action adds a PR comment which shows what will happen if the PR is merged.
The comment is updated when labels are added or removed, if the workflow has
the appropriate triggers (see section "Usage").

The action can optionally trigger follow-up workflows (for example if you want
to automatically create a release after a new tag has been created). This
feature requires that any workflows that should be triggered by the action
have the `workflow_dispatch` trigger option.

## Usage

TODO: Update this section
To use the action with the default configuration you can use the following
workflow config:

```yaml
on:
Expand All @@ -29,12 +38,47 @@ on:
- closed

steps:
- name: Checkout
id: checkout
uses: actions/checkout@v3
- name: Create new tag
uses: projectsyn/pr-label-tag-action@v1
```

- name: Create new version
uses: projectsyn/pr-label-tag-action@v1 # Commit with the `v1` tag
### Triggering follow-up actions

```yaml
on:
pull_request:
types:
- synchronize
- labeled
- unlabeled
- closed

steps:
- name: Create new tag
uses: projectsyn/pr-label-tag-action@v1
with:
milliseconds: 1000
trigger: |
Release
```

See [this repository's "Release" workflow](https://github.com/projectsyn/pr-label-tag-action/blob/main/.github/workflows/release.yml)
for an example workflow that is be triggered correctly on both manually pushed
tags, and tags created by this action.

## Action inputs

| Name | Description | Default |
|------|-------------|---------|
| `github-token` | Token to access GitHub | `github.token` |
| `patch-label` | Label which indicates a patch-level SemVer bump | `bump:patch` |
| `minor-label` | Label which indicates a minor-level SemVer bump | `bump:minor` |
| `major-label` | Label which indicates a major-level SemVer bump | `bump:major` |
| `trigger` | Workflow names of workflows that should be triggered when a new tag is created. Multiple workflows can be specified on separate lines. | "" |
| `release-comment` | Comment that gets posted when a tag will be pushed on merge | "🚀 Merging this PR will release \`\<next-version\>\`" |
| `released-comment` | Comment that gets posted when a tag has been pushed | "🚀 This PR has been released as \[\`\<next-version\>\`\]\(\<release-url\>\)" |
| `unmerged-comment` | Comment that gets posted when a labeled PR gets closed unmerged | "This PR has been closed unmerged. No new release will be created for these changes" |

For inputs `release-comment`, `released-comment` and `unmerged-comment` the action supports the following placeholders:

- `<next-version>` is replaced with the computed new version
- `<release-url>` is replaced with the URL to the new tag
Loading
Loading