Skip to content

Commit

Permalink
Merge pull request #4 from asartalo/moreLogical
Browse files Browse the repository at this point in the history
Dealing with projects that have build numbers
  • Loading branch information
asartalo authored Jan 26, 2022
2 parents 7959e52 + 3fb85e7 commit e86834c
Show file tree
Hide file tree
Showing 13 changed files with 383 additions and 154 deletions.
227 changes: 112 additions & 115 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: build

on:
push:
branches: [ '*' ]
branches: ["*"]
pull_request:
branches: [ '*' ]
branches: ["*"]

jobs:
commitlint:
Expand All @@ -23,42 +23,40 @@ jobs:
branch: ${{ steps.branchinfo.outputs.branch }}

steps:
- uses: nelonoel/branch-name@v1.0.1

- uses: nelonoel/branch-name@v1.0.1
- name: Store the branch name
id: branchinfo
run: echo "::set-output name=branch::${BRANCH_NAME}"

- name: Store the branch name
id: branchinfo
run: echo "::set-output name=branch::${BRANCH_NAME}"
- name: Check if we were able to save branch info
run: echo ${{ steps.branchinfo.outputs.branch }}

- name: Check if we were able to save branch info
run: echo ${{ steps.branchinfo.outputs.branch }}
- name: Setup Dart SDK
uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d

- uses: cedx/setup-dart@v2
with:
release-channel: stable

- uses: actions/checkout@v2
- uses: actions/checkout@v2

- name: Get dependencies
run: pub get
- name: Get dependencies
run: pub get

- name: Check dart formatting
run: dart format --set-exit-if-changed .
- name: Check dart formatting
run: dart format --set-exit-if-changed .

- name: Statically analyze the Dart code for any errors.
run: dart analyze .
- name: Statically analyze the Dart code for any errors.
run: dart analyze .

- name: Run Tests with coverage
run: dart test --coverage="coverage"
- name: Run Tests with coverage
run: dart test --coverage="coverage"

- name: Prepare coverage
run: pub run coverage:format_coverage --lcov --in=coverage --out=lcov.info --packages=.packages --report-on=lib
- name: Prepare coverage
run: pub run coverage:format_coverage --lcov --in=coverage --out=lcov.info --packages=.packages --report-on=lib

- name: Upload coverage
uses: coverallsapp/github-action@v1.1.2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: lcov.info
- name: Upload coverage
uses: coverallsapp/github-action@v1.1.2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: lcov.info

release:
name: Release
Expand All @@ -67,90 +65,89 @@ jobs:
if: ${{ needs.test.outputs.branch == 'main' }}

steps:
- run: echo ${{ needs.test.outputs.branch }}

- uses: cedx/setup-dart@v2
with:
release-channel: stable

- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Get dependencies
run: pub get

- name: Get current version
id: currentVersion
run: echo "::set-output name=value::$(pub run release_tools current_version)"

- name: Get commitId of last tag of that version
id: lastCommitId
run: echo "::set-output name=value::$(pub run release_tools remote_tag_id ${{ steps.currentVersion.outputs.value }})"

- name: Use commitId to check if we should release
id: shouldRelease
run: echo "::set-output name=value::$(pub run release_tools should_release --from ${{ steps.lastCommitId.outputs.value }})"

- run: echo "Should we release? ${{ steps.shouldRelease.outputs.value }}"

- name: If we should release get the next version
if: steps.shouldRelease.outputs.value == 'yes'
id: nextVersion
run: echo "::set-output name=value::$(pub run release_tools next_version --from ${{ steps.lastCommitId.outputs.value }})"

- run: echo "RELEASING ${{ steps.nextVersion.outputs.value }}"

- name: Update version
if: steps.shouldRelease.outputs.value == 'yes'
id: updateVersion
run: pub run release_tools update_version ${{ steps.nextVersion.outputs.value }}

- name: Write changelog
id: changelog
if: steps.shouldRelease.outputs.value == 'yes'
run: |
output=$(pub run release_tools changelog --from ${{ steps.lastCommitId.outputs.value }} ${{ steps.nextVersion.outputs.value }})
output="${output//'%'/'%25'}"
output="${output//$'\n'/'%0A'}"
output="${output//$'\r'/'%0D'}"
echo "::set-output name=summary::$output"
- name: Commit Release
if: steps.shouldRelease.outputs.value == 'yes'
run: |
git diff
git config user.name github-actions
git config user.email github-actions@github.com
git add .
git commit -m "chore(release): release for ${{ steps.nextVersion.outputs.value }}"
git push
- name: Create Release
if: steps.shouldRelease.outputs.value == 'yes'
id: createRelease
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.nextVersion.outputs.value }}
release_name: Release ${{ steps.nextVersion.outputs.value }}
body: |
Changes in this Release
${{ steps.changelog.outputs.summary }}
draft: false
prerelease: false

- name: Setup credentials
if: steps.shouldRelease.outputs.value == 'yes'
run: |
mkdir -p ~/.pub-cache
cat <<EOF > ~/.pub-cache/credentials.json
${{ secrets.PUB_CREDENTIALS }}
EOF
- name: Publish package
if: steps.shouldRelease.outputs.value == 'yes'
run: pub publish -f
- run: echo ${{ needs.test.outputs.branch }}

- name: Setup Dart SDK
uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d

- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Get dependencies
run: pub get

- name: Get current version
id: currentVersion
run: echo "::set-output name=value::$(pub run release_tools current_version)"

- name: Get commitId of last tag of that version
id: lastCommitId
run: echo "::set-output name=value::$(pub run release_tools remote_tag_id ${{ steps.currentVersion.outputs.value }})"

- name: Use commitId to check if we should release
id: shouldRelease
run: echo "::set-output name=value::$(pub run release_tools should_release --from ${{ steps.lastCommitId.outputs.value }})"

- run: echo "Should we release? ${{ steps.shouldRelease.outputs.value }}"

- name: If we should release get the next version
if: steps.shouldRelease.outputs.value == 'yes'
id: nextVersion
run: echo "::set-output name=value::$(pub run release_tools next_version --from ${{ steps.lastCommitId.outputs.value }})"

- run: echo "RELEASING ${{ steps.nextVersion.outputs.value }}"

- name: Update version
if: steps.shouldRelease.outputs.value == 'yes'
id: updateVersion
run: pub run release_tools update_version ${{ steps.nextVersion.outputs.value }}

- name: Write changelog
id: changelog
if: steps.shouldRelease.outputs.value == 'yes'
run: |
output=$(pub run release_tools changelog --from ${{ steps.lastCommitId.outputs.value }} ${{ steps.nextVersion.outputs.value }})
output="${output//'%'/'%25'}"
output="${output//$'\n'/'%0A'}"
output="${output//$'\r'/'%0D'}"
echo "::set-output name=summary::$output"
- name: Commit Release
if: steps.shouldRelease.outputs.value == 'yes'
run: |
git diff
git config user.name github-actions
git config user.email github-actions@github.com
git add .
git commit -m "chore(release): release for ${{ steps.nextVersion.outputs.value }}"
git push
- name: Create Release
if: steps.shouldRelease.outputs.value == 'yes'
id: createRelease
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.nextVersion.outputs.value }}
release_name: Release ${{ steps.nextVersion.outputs.value }}
body: |
Changes in this Release
${{ steps.changelog.outputs.summary }}
draft: false
prerelease: false

- name: Setup credentials
if: steps.shouldRelease.outputs.value == 'yes'
run: |
mkdir -p ~/.pub-cache
cat <<EOF > ~/.pub-cache/credentials.json
${{ secrets.PUB_CREDENTIALS }}
EOF
- name: Publish package
if: steps.shouldRelease.outputs.value == 'yes'
run: pub publish -f
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Files and directories created by pub
.dart_tool/
.packages
.vscode

# Conventional directory for build outputs
build/
Expand Down
45 changes: 31 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
A collection of scripts to help with creating releases for publishing libraries and dart packages.


[![build](https://github.com/asartalo/release_tools/actions/workflows/ci.yml/badge.svg)](https://github.com/asartalo/conventional/actions/workflows/ci.yml) [![Coverage Status](https://coveralls.io/repos/github/asartalo/release_tools/badge.svg?branch=main)](https://coveralls.io/github/asartalo/release_tools?branch=main)
[![build](https://github.com/asartalo/release_tools/actions/workflows/ci.yml/badge.svg)](https://github.com/asartalo/release_tools/actions/workflows/ci.yml) [![Coverage Status](https://coveralls.io/repos/github/asartalo/release_tools/badge.svg?branch=main)](https://coveralls.io/github/asartalo/release_tools?branch=main)
[![Pub](https://img.shields.io/pub/v/release_tools.svg)](https://pub.dev/packages/release_tools)
## Features

Expand Down Expand Up @@ -38,26 +38,20 @@ $ pub global activate release_tools 0.2.5

### update_version

The following command will update the version on `pubspec.yaml` to version 1.0.1
The following command will update the version on `pubspec.yaml` on the current directory to version 1.0.1

```sh
$ release_tools update_version 1.0.1
```

### next_version

If you leave out the version to increment from, it will attempt to obtain the version from pubspec.yaml

```sh
$ release_tools next_version 1.0.1
$ release_tools next_version
```

The following command will incremeent the commands based on the commit logs that follow the conventional commit spec.

```sh
$ release_tools next_version 1.0.1
# 1.1.0
```
If you don't pass the version to increment from, it will attempt to get the version from `pubspec.yaml`. The script will return the next version based on the releasable commit logs that follow the conventional commit spec.

For example, if the commit logs contain a commit with the following message:

Expand All @@ -72,14 +66,35 @@ BREAKING-CHANGE: this changes everything
2.0.0
```

By default it considers all the logs from the beginning but you can also specify a starting range:
By default, `next_version` considers all the logs from the beginning of the commit history but you can also specify a starting range:

```sh
$ release_tools next_version --from=abcde1234 1.0.1
```

...where `--from` should point to a commit id.

It will also increment the build number if the version on the `pubspec.yaml` or the version passed has it if there are releasable commits.

```sh
$ release_tools next_version 1.0.1+1
# 1.1.0+2
```

If you don't want this behavior, pass the `--freezeBuild` flag.

```sh
$ release_tools next_version --freezeBuild 1.0.1+1
# 1.1.0+1
```

To output just the version without the build number, pass the `--noBuild` flag.

```sh
$ release_tools next_version --noBuild 1.0.1+1
# 1.1.0
```

### should_release

The following will print 'yes' to stdout if there are releasable commits, or 'no' if there are none.
Expand All @@ -91,9 +106,11 @@ $ release_tools should_release --from=abcde1234
no
```

"Releasable" here means that the commit logs contain at least one `fix` (PATCH), `feat` (MINOR), or `BREAKING` (MAJOR) logs as described in the conventional commits spec.

### changelog

The following will update the changelog based on the commit logs that follow the Conventional Commit spec.
The following will update the changelog based on the releasable commits.

```sh
$ release_tools changelog 2.0.1
Expand Down Expand Up @@ -165,9 +182,9 @@ $ release_tools current_version
Complete release preparation logic with the following steps:

1. Get the current version
2. Get the commits from the last tag or, if a tag is not available for the last release, from the beginning of commit history
2. Get the commits from the last version tag or, if a version tag is not available for the last release, it will get them from the beginning of the commit history
3. Check if a release is appropriate and if so...
4. Update version on pubspec
4. Update version on pubspec including incrementing the build number
5. Create summary changelog from the commits

```sh
Expand Down
4 changes: 3 additions & 1 deletion lib/changelog_command.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:conventional/conventional.dart';
import 'package:pub_semver/pub_semver.dart';
import 'package:release_tools/version_helpers.dart';

import 'git_exec.dart';
import 'help_footer.dart';
Expand Down Expand Up @@ -65,7 +67,7 @@ release_tools changelog --from=3682c64 2.0.1
}) {
return writeChangelogToFile(
commits: commits,
version: version,
version: versionWithoutBuild(Version.parse(version)).toString(),
now: now,
file: project.changelog(),
);
Expand Down
Loading

0 comments on commit e86834c

Please sign in to comment.