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

👷 only run CI publish / --dry-run when a package's version changes #424

Merged
merged 40 commits into from
May 15, 2023

Conversation

techouse
Copy link
Collaborator

@techouse techouse commented May 14, 2023

The idea here is to only run dart pub publish or dart pub publish --dry-run when the package's version in pubspec.yaml is higher than the base branch's.

Example:

package base version PR version publish
chopper 6.1.2 6.1.3
chopper_generator 6.0.1 6.0.1
chopper_built_value 1.2.1 1.3.0

The base branch's version is obtained using a separate job that first checks out the base branch

- id: checkout
  uses: actions/checkout@v3
  with:
    ref: ${{ github.event.pull_request.base.ref }}

and then parses its pubspec.yaml file

- name: Load base version
  id: load_base_version
  run: |
    set -e
    echo "BASE_VERSION_${{ matrix.package }}=$(awk '/^version: / {print $2}' ${{ matrix.package }}/pubspec.yaml)" >> $GITHUB_OUTPUT

That base version is then exported as an output

outputs:
  BASE_VERSION_chopper: ${{ steps.load_base_version.outputs.BASE_VERSION_chopper }}
  BASE_VERSION_chopper_generator: ${{ steps.load_base_version.outputs.BASE_VERSION_chopper_generator }}
  BASE_VERSION_chopper_built_value: ${{ steps.load_base_version.outputs.BASE_VERSION_chopper_built_value }}

so that it can be consumed by another job that does the version comparison

- name: Load this version
  id: load_this_version
  run: |
    set -e
    echo "THIS_VERSION=$(awk '/^version: / {print $2}' ${{ matrix.package }}/pubspec.yaml)" >> $GITHUB_ENV
- name: Compare versions
  id: compare_versions
  env:
    BASE_VERSION_chopper: ${{ needs.get_base_version.outputs.BASE_VERSION_chopper }}
    BASE_VERSION_chopper_generator: ${{ needs.get_base_version.outputs.BASE_VERSION_chopper_generator }}
    BASE_VERSION_chopper_built_value: ${{ needs.get_base_version.outputs.BASE_VERSION_chopper_built_value }}
  run: |
    set -e
    pushd tool || exit
    dart pub get
    echo "IS_VERSION_GREATER=$(dart run compare_versions.dart $THIS_VERSION $BASE_VERSION_${{ matrix.package }})" >> $GITHUB_ENV
    popd || exit

It uses pub_semver to determine whether or not the version of the PR is higher than the version of the base branch. It's slower and more complex than just using printf or regex but then again it's also safer as it comes from the Dart team.

Also using Github action matrices here for better readability.

strategy:
  matrix:
    package: [ chopper, chopper_generator, chopper_built_value ]

@techouse techouse added the ci Continuous Integration label May 14, 2023
@techouse techouse changed the title 👷 only publish when version changes 👷 only run CI publish / publish --dry-run when a package's version changes May 14, 2023
@codecov
Copy link

codecov bot commented May 14, 2023

Codecov Report

Merging #424 (65c5101) into develop (b8fd63a) will increase coverage by 4.44%.
The diff coverage is 95.09%.

@@             Coverage Diff             @@
##           develop     #424      +/-   ##
===========================================
+ Coverage    89.18%   93.63%   +4.44%     
===========================================
  Files            5        8       +3     
  Lines          333      440     +107     
===========================================
+ Hits           297      412     +115     
+ Misses          36       28       -8     
Impacted Files Coverage Δ
chopper/lib/src/interceptor.dart 73.33% <71.42%> (-7.16%) ⬇️
chopper/lib/src/response.dart 88.88% <88.88%> (+22.22%) ⬆️
chopper/lib/src/base.dart 94.73% <94.73%> (+1.08%) ⬆️
chopper/lib/src/http_logging_interceptor.dart 95.91% <95.91%> (ø)
chopper/lib/src/extensions.dart 100.00% <100.00%> (ø)
chopper/lib/src/request.dart 100.00% <100.00%> (+8.53%) ⬆️
chopper/lib/src/utils.dart 100.00% <100.00%> (ø)
chopper_built_value/lib/chopper_built_value.dart 96.66% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@techouse techouse marked this pull request as ready for review May 14, 2023 18:22
@techouse techouse changed the title 👷 only run CI publish / publish --dry-run when a package's version changes 👷 only run CI publish / --dry-run when a package's version changes May 14, 2023
@JEuler
Copy link
Collaborator

JEuler commented May 15, 2023

That was a hard battle. :)

@techouse techouse merged commit 0145064 into lejard-h:develop May 15, 2023
@techouse techouse deleted the chore/streamline-publishing branch May 15, 2023 05:18
@techouse
Copy link
Collaborator Author

techouse commented May 15, 2023

That was a hard battle. :)

Sadly one can only test by triggering the CI.

PS #425 will need to be merged as well because it somehow slipped in there when I was copying the dry run workflow into the publish workflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci Continuous Integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants