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

Milestone: GitHub action #52

Merged
merged 52 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
f9300cb
chore: add required files to start developing custom GitHub action
dloez Oct 9, 2023
cbedbdf
ci: debug CI environment variables
dloez Oct 9, 2023
03ce1a8
ci: use github context to get action ref
dloez Oct 9, 2023
3cc7a70
ci: use composite action to be able to use github context
dloez Oct 9, 2023
daa00f6
ci: fix typo
dloez Oct 9, 2023
a49df7f
ci: fix typo
dloez Oct 9, 2023
166d222
ci: fix typo
dloez Oct 9, 2023
2b869c7
ci: pass action ref to composite action env
dloez Oct 9, 2023
43deff8
ci: use `github.context.ref`
dloez Oct 9, 2023
fe2c1eb
ci: test script installation in composite action
dloez Oct 10, 2023
60e9b2b
ci: fix missing `shell` fields
dloez Oct 10, 2023
affe370
ci: fix typo
dloez Oct 10, 2023
d7f77b0
ci: add checkout to research workflow
dloez Oct 10, 2023
279f17a
chore: remove node action files
dloez Oct 10, 2023
ea12124
ci: define action inputs and print them for debugging
dloez Oct 10, 2023
a0aee7f
ci: debug env variables
dloez Oct 10, 2023
1731e42
ci: use `$GITHUB_REPOSITORY` instead of hardcoding repo
dloez Oct 10, 2023
dc5445d
ci: obtain action reference and define all outputs
dloez Oct 10, 2023
07aaee9
ci: use defined outputs as action outputs
dloez Oct 10, 2023
9387626
refactor: change ´created-tag´ for ´tag-created´
dloez Oct 10, 2023
20e0e58
feat: use inputs to control tag-track execution in github action
dloez Oct 10, 2023
79515f6
fix: replaced `\n` characters in errors
dloez Oct 10, 2023
697dff9
ci: add git author configuration to research workflow
dloez Oct 10, 2023
9e7833c
fix: evaluate input `create-tag` rather than checking if it has a value
dloez Oct 10, 2023
f0d55e8
feat: add `compile` action input and functionallity
dloez Oct 10, 2023
5076dad
feat: implement `useCache` action input for caching compilations
dloez Oct 10, 2023
88cdb06
feat: install rust toolchain only if we did not have a cache hit
dloez Oct 11, 2023
17c7451
feat: implement cache for downloaded binaries
dloez Oct 11, 2023
bf6c84c
ci: use compile mode for researching github action
dloez Oct 11, 2023
7ac9eff
feat: implement `--github-api-url` argument as described in #38
dloez Oct 11, 2023
59b2f58
fix: glob pattern used to generate compile cache key
dloez Oct 11, 2023
5d1df86
feat: add skipped commits to JSON output as described in #40 and disp…
dloez Oct 11, 2023
631a513
feat: display configuration in output when using `json` format as des…
dloez Oct 11, 2023
aba9228
feat: add runner OS and ARCH to cache key to support MAC os runners a…
dloez Oct 11, 2023
b99a1c3
ci: change research workflow runner to `macos-latest`
dloez Oct 11, 2023
88c3799
ci: change to windows runner
dloez Oct 11, 2023
af8eeaf
fix: change repository slashes substitution in windows runners
dloez Oct 11, 2023
62f1210
feat: add action support for windows runners in download mode
dloez Oct 12, 2023
3e3377e
feat: reduce compile cache keys
dloez Oct 12, 2023
ad23027
fix: capture tag-track call errors
dloez Oct 12, 2023
79a23d2
feat: add action notices to display new version and tag
dloez Oct 12, 2023
c60bc70
fix: skipped empty commit when there are no commits
dloez Oct 12, 2023
463aa22
feat: create new tags following `tag_pattern` as described in #49
dloez Oct 12, 2023
f55c36f
feat: change when the new tag notice is displayed
dloez Oct 12, 2023
8f011d6
feat: support automatically configuring git author information
dloez Oct 12, 2023
b13fcde
feat: add documentation for action and fixed action typos
dloez Oct 12, 2023
8e72af3
ci: use new action in workflows
dloez Oct 13, 2023
47794c5
refactor: add clippy suggestions
dloez Oct 13, 2023
5274f0f
feat: modify obtention of action reference
dloez Oct 13, 2023
56db80f
docs: usage of `tag-track-version` action input
dloez Oct 13, 2023
69fb68e
feat: test new obtention method of `github.action_ref`
dloez Oct 13, 2023
a8ababf
feat: use `github.action_ref` to get action reference
dloez Oct 13, 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
16 changes: 7 additions & 9 deletions .github/workflows/build_lint_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,15 @@ jobs:
- name: Install aarch64-unknown-linux-gnu requisites
run: sudo apt update && sudo apt-get install -y g++-aarch64-linux-gnu
if: matrix.os-target.target == 'aarch64-unknown-linux-gnu'
- name: Run trag-track
- name: Run Tag Track
id: tag-track
run: |
exec 5>&1
output=$(cargo run -- --github-repo dloez/tag-track --github-token ${{ github.token }} --output-format json | tee >(cat - >&5))
echo $output
echo "new_version=$(echo $output | jq -r '.new_version')" >> $GITHUB_OUTPUT
- name: Output from tag-track
run: echo ${{ steps.tag-track.outputs.new_version }}
uses: ./
with:
github-token: ${{ github.token }}
compile: true
use-cache: true
- name: Run cargo build
run: TAG_TRACK_VERSION=${{ steps.tag-track.outputs.new_version }} cargo build --release --target ${{ matrix.os-target.target }}
run: TAG_TRACK_VERSION=${{ steps.tag-track.outputs.new-version }} cargo build --release --target ${{ matrix.os-target.target }}
- name: Upload artifacts for reuse in release job
uses: actions/upload-artifact@v3
with:
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/research.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Research creation of custom GitHub action
on:
push:
branches:
- github-action-research
jobs:
research:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure git author
run: |
git config user.name example
git config user.email example
- uses: dloez/tag-track@github-action-research
with:
compile: true
use-cache: true
create-tag: true
- name: Check git author
run: |
echo "::debug::Git author name: $(git config user.name)"
echo "::debug::Git author email: $(git config user.email)"
51 changes: 19 additions & 32 deletions .github/workflows/tag_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,37 @@ jobs:
call-build_lint:
uses: ./.github/workflows/build_lint_test.yml
secrets: inherit
create_tag:
create-tag:
runs-on: ubuntu-latest
needs: call-build_lint
permissions:
contents: write
outputs:
created_tag: ${{ steps.tag-track.outputs.created_tag }}
new_version: ${{ steps.tag-track.outputs.new_version }}
tag-created: ${{ steps.tag-track.outputs.tag-created }}
new-tag: ${{ steps.tag-track.outputs.new-tag }}
new-version: ${{ steps.tag-track.outputs.new-version }}
steps:
- uses: actions/checkout@v3
- name: Configure git author
run: |
git config user.name github-actions
git config user.email github-actions@github.com
- name: Setup rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.71.0
targets: ${{ matrix.os-target.target }}
- uses: Swatinem/rust-cache@v2
- name: Run trag-track
- name: Run Tag Track
id: tag-track
run: |
exec 5>&1
output=$(cargo run -- --create-tag --github-repo dloez/tag-track --github-token ${{ github.token }} --output-format json | tee >(cat - >&5))
echo "created_tag=$(echo $output | jq -r '.created_tag')" >> $GITHUB_OUTPUT
echo "new_version=$(echo $output | jq -r '.new_version')" >> $GITHUB_OUTPUT
- name: Output from tag-track
run: |
echo ${{ steps.tag-track.outputs.created_tag }}
echo ${{ steps.tag-track.outputs.new_version }}
- name: Push tags
run: git push origin --tags
uses: ./
with:
create-tag: true
push-tag: true
github-token: ${{ github.token }}
compile: true
use-cache: true
release:
runs-on: ubuntu-latest
permissions:
contents: write
needs: create_tag
if: ${{ needs.create_tag.outputs.created_tag == 'true' }}
needs: create-tag
if: ${{ needs.create-tag.outputs.tag-created == 'true' }}
steps:
- uses: actions/checkout@v3
- name: Generate release notes
run: |
sed 's/{version}/${{ needs.create_tag.outputs.new_version }}/g' ${{ github.workspace }}/.github/release_notes.template \
sed 's/{version}/${{ needs.create-tag.outputs.new-version }}/g' ${{ github.workspace }}/.github/release_notes.template \
> ${{ github.workspace }}/.github/release_notes.txt
- name: Create release
uses: softprops/action-gh-release@v1
Expand All @@ -59,13 +46,13 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
generate_release_notes: true
name: Tag Track - ${{ needs.create_tag.outputs.new_version }}
tag_name: ${{ needs.create_tag.outputs.new_version }}
name: Tag Track - ${{ needs.create-tag.outputs.new-version }}
tag_name: ${{ needs.create-tag.outputs.new-tag }}
body_path: ${{ github.workspace }}/.github/release_notes.txt
target_commitish: ${{ github.base_ref }}
prerelease: true
upload-to-release:
needs: [create_tag, release]
needs: [create-tag, release]
permissions:
contents: write
strategy:
Expand All @@ -86,7 +73,7 @@ jobs:
run: |
mv ${{ github.workspace }}/target/${{ matrix.target }}/release/tag-track${{ matrix.target == 'x86_64-pc-windows-msvc' && '.exe' || '' }} \
tag-track_${{ matrix.target }}${{ matrix.target == 'x86_64-pc-windows-msvc' && '.exe' || '' }}
gh release upload ${{ needs.create_tag.outputs.new_version }} \
gh release upload ${{ needs.create-tag.outputs.new-version }} \
tag-track_${{ matrix.target }}${{ matrix.target == 'x86_64-pc-windows-msvc' && '.exe' || '' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
/tmp
/node_modules
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
46 changes: 40 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
{
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer",
"editor.formatOnSave": true
},
"rust-analyzer.showUnlinkedFileNotification": false
}
"editor.formatOnSave": false,
"editor.insertSpaces": true,
"editor.tabSize": 4,

"[javascript]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.tabSize": 2
},

"[typescript]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.tabSize": 2
},

"[json]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.tabSize": 2
},

"[jsonc]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.tabSize": 2
},

"[yaml]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.tabSize": 2
},

"[rust]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "rust-lang.rust-analyzer"
},
"rust-analyzer.showUnlinkedFileNotification": false
}
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

The MIT License (MIT)

Copyright (c) 2018 GitHub, Inc. and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
80 changes: 77 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ tag-track
```
This will use the latest closest tag and the commit messages between that tag and the current commit to calculate the version bump.

Refer to the [GitHub Action section](#github-action) for information on how to use Tag Track inside a GitHub actions workflow.

### Additional arguments
- `--create-tag`: Automatically create a git tag with the calculated version bump. If no version bump was calculated, the tag creation will be skipped.
- `--github-repo`: Use GitHub REST API instead of git history to calculate the version bump. The value should be `user-organization/repository-name`, for example `dloez/tag-track`.
Expand All @@ -25,8 +27,8 @@ This will use the latest closest tag and the commit messages between that tag an
### Configuration
Additionally, you can create a `track.yaml` or `track.yml` file to configure:

- Tag format. Use the `tag_pattern` field to specify a Regex pattern to get the version from the tag name. The pattern should contain naming capturing groups to capture the required fields. Read more about the required groups for this field in the (Naming capturing groups section)[#-Naming-capturing-groups]. The default pattern is `(?<version>.*)`.
- Commit pattern. Use the `commit_pattern` field to specify a Regex pattern to get the commit fields specified in the [conventional commit specification](https://www.conventionalcommits.org/en/v1.0.0). The pattern should contain naming capturing groups to capture the required fields. Read more about the required groups for this field in the [Naming capturing groups section](#-Naming-capturing-groups). Read more about the required groups for this field in the [Naming capturing groups section](#-Naming-capturing-groups). The default pattern is `^(?<type>[a-zA-Z]*)(?<scope>\(.*\))?(?<breaking>!)?:(?<description>[\s\S]*)$`, this pattern tries to follow the [conventional commit specification](https://www.conventionalcommits.org/en/v1.0.0/#specification) as close **and simple** as possible while allowing to use custom types.
- Tag format. Use the `tag_pattern` field to specify a Regex pattern to get the version from the tag name. The pattern should contain naming capturing groups to capture the required fields. Read more about the required groups for this field in the [Naming capturing groups section](#naming-capturing-groups). The default pattern is `(?<version>.*)`.
- Commit pattern. Use the `commit_pattern` field to specify a Regex pattern to get the commit fields specified in the [conventional commit specification](https://www.conventionalcommits.org/en/v1.0.0). The pattern should contain naming capturing groups to capture the required fields. Read more about the required groups for this field in the [Naming capturing groups section](#naming-capturing-groups). The default pattern is `^(?<type>[a-zA-Z]*)(?<scope>\(.*\))?(?<breaking>!)?:(?<description>[\s\S]*)$`, this pattern tries to follow the [conventional commit specification](https://www.conventionalcommits.org/en/v1.0.0/#specification) as close **and simple** as possible while allowing to use custom types.
- Version bump rules. Use the `bump_rules` field to specify the rules used to calculate the version bump. If a rule condition is missing, that condition will not be evaluated. Each rule has the following fields:
* `bump`: Version section to bump. Possible values are `major`, `minor`, and `patch`. Example: `bump: major` - will increase the `major` section of the semantic version if all rule conditions pass.
* `types`: Condition - List of commit types. An `OR` operation will be used between list types. Example: `types: [feat, fix]` - will pass the condition if the commit type is `feat` or `fix`.
Expand Down Expand Up @@ -54,6 +56,78 @@ bump_rules: '^(?<type>[a-zA-Z]*)(?<scope>\(.*\))?(?<breaking>!)?:(?<description>
if_breaking_description: true
```

## GitHub Action
We provide a custom GitHub action to easily call Tag Track in GitHub actions workflows. This action can download or compile the version of Tag Track based on the specified action version. This action has been tested in `Linux`, `MacOS`, and `Windows` hosted runners.

### Pre-requisites
In order for Tag Track to work, the repository needs to be checked out before calling Tag Tack.

### Inputs
- `create-tag`: Create a new tag with bumped version. Defaults to `false`.
- `push-tag`: Push the new tag to the repository if `create-tag` is used. Defaults to `false`.
- `github-repo`: Github repository in the format owner/repo. Defaults to the repository that triggers the action.
- `github-api-url`: Github API URL. Defaults to the value of the environment variable `GITHUB_API_URL`.
- `github-token`: Github token to authorize requests to GitHub REST API. Can cause rate limit to be increased.
- `commit-sha`: Commit SHA from where the version bump will be calculated. Defaults to the commit SHA that triggers the action.
- `compile`: Instead of downloading the binary, compile it from source. Defaults to `false`.
- `use-cache`: Save binary in cache to avoid downloading or compiling it every time. Defaults to `false`.
- `git-author-name`: Name of the author for tags created by Tag Track. Defaults to `github-actions`.
- `git-author-email`: Email of the author for tags created by Tag Track. Defaults to `github-actions@github.com`.

The action will automatically reset to previous git author information as soon as it finishes.

If you want to modify the different configuration properties, create a `track.yaml` or `track.yml` file in the root of the repository. Refer to the [Configuration section](#configuration) for more information.

### Outputs
- `tag-created`: True if a new tag was created.
- `new-tag`: Tag name if a new tag was created.
- `old-version`: Old version before calculating the version bump.
- `new-version`: New version after calculating the version bump.
- `skipped-commits`: List of commits that were skipped because they don't match the commit pattern.
- `error`: Error message if something went wrong.

The action will create notices to inform the user about the version bump and if a new tag was created and pushed. In case there are any skipped commits, a new warning for each of the commits will be created.

### Examples
The version shown on these examples are only for demostration pourposes, use [the latest stable release version](https://github.com/dloez/tag-track/releases/latest) in your workflows. If you want to use any other version that does not have a release, use the compile mode.

- Checkout repository, calculate version bump, and create and push a new tag with the bumped version. Use cache to save binary and avoid downloading it every time:
```yaml
- name: Checkout
uses: actions/checkout@v4
- name: Tag Track
uses: dloez/tag-track@v1.0.0
with:
create-tag: true
push-tag: true
use-cache: true
```

- Checkout repository, calculate version bump, and create a new tag with the bumped version. Use cache to save binary and avoid downloading it every time. Instead of using Tag Track to push the image, push it manually:
```yaml
- name: Checkout
uses: actions/checkout@v4
- name: Tag Track
uses: dloez/tag-track@v1.0.0
with:
create-tag: true
use-cache: true
- name: Push tags
run: git push origin --tags
```

- Checkout repository, calculate version bump, and create and push a new tag with the bumped version. Instead of using a release, use the main branch and the compile mode with cache to avoid compiling it every time:
```yaml
- name: Checkout
uses: actions/checkout@v4
- name: Tag Track
uses: dloez/tag-track@v1.0.0
with:
create-tag: true
compile: true
use-cache: true
```

## Naming capturing groups
Tag track uses [naming capturing groups](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Named_capturing_group) to get the required information from tags and commits. The naming capturing groups allows the user to define custom patterns (even with different field ordering) and still get the required information. These are the naming capturing groups used by Tag track:
- `tag_pattern`:
Expand All @@ -67,7 +141,7 @@ Tag track uses [naming capturing groups](https://developer.mozilla.org/en-US/doc
## Project stability and current status
Currently, Tag track has a high work-in-progress status, thus we are marking releases as pre-releases. There will be API changes and non-backward compatibility changes during this phase. Here is a list of features and improvements that we want to make before the release of Tag track `1.0.0`:

- [ ] Custom GitHub actions with improved API to use inside GitHub actions jobs.
- [x] Custom GitHub actions with improved API to use inside GitHub actions jobs.
- [ ] More remote sources such as GitLab, Gitea, etc.
- [x] Custom rules to calculate version bumps based on conventional commit messages.
- [x] Support multiple tag formats. Currently only tags that follow the [semantic versioning 2.0](https://semver.org) can be parsed.
Expand Down
Loading
Loading