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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
ebb39b2
:construction_worker: only publish when version changes
techouse May 14, 2023
39155b6
:construction_worker: only publish when version changes
techouse May 14, 2023
1175a11
:construction_worker: only publish when version changes
techouse May 14, 2023
31b27a9
:construction_worker: only publish when version changes
techouse May 14, 2023
3f03641
:construction_worker: only publish when version changes
techouse May 14, 2023
495875a
:construction_worker: only publish when version changes
techouse May 14, 2023
b85deb4
:construction_worker: only publish when version changes
techouse May 14, 2023
7de4371
:construction_worker: only publish when version changes
techouse May 14, 2023
6cce396
:construction_worker: only publish when version changes
techouse May 14, 2023
493cecc
:construction_worker: only publish when version changes
techouse May 14, 2023
89dca58
:construction_worker: only publish when version changes
techouse May 14, 2023
d7fb264
:construction_worker: only publish when version changes
techouse May 14, 2023
407d8e1
:construction_worker: only publish when version changes
techouse May 14, 2023
23f51d2
:construction_worker: only publish when version changes
techouse May 14, 2023
4669e2e
:construction_worker: only publish when version changes
techouse May 14, 2023
3630d55
:construction_worker: only publish when version changes
techouse May 14, 2023
04ebe29
:construction_worker: only publish when version changes
techouse May 14, 2023
5262227
:construction_worker: only publish when version changes
techouse May 14, 2023
883373e
:construction_worker: only publish when version changes
techouse May 14, 2023
2197f9a
:construction_worker: only publish when version changes
techouse May 14, 2023
0fc5c09
:construction_worker: only publish when version changes
techouse May 14, 2023
d9bb29a
:construction_worker: only publish when version changes
techouse May 14, 2023
074850d
:construction_worker: only publish when version changes
techouse May 14, 2023
419d0e5
:construction_worker: only publish when version changes
techouse May 14, 2023
ab906d0
:construction_worker: only publish when version changes
techouse May 14, 2023
472bf5b
:construction_worker: only publish when version changes
techouse May 14, 2023
cbff096
:construction_worker: only publish when version changes
techouse May 14, 2023
2a38563
:construction_worker: only publish when version changes
techouse May 14, 2023
778c76c
:construction_worker: only publish when version changes
techouse May 14, 2023
853d39e
:construction_worker: only publish when version changes
techouse May 14, 2023
69e76c0
:construction_worker: only publish when version changes
techouse May 14, 2023
6aa5e68
:construction_worker: only publish when version changes
techouse May 14, 2023
79c42af
:construction_worker: only publish when version changes
techouse May 14, 2023
9e7abe3
:construction_worker: only publish when version changes
techouse May 14, 2023
3e6f50e
:construction_worker: only publish when version changes
techouse May 14, 2023
ea10aa8
:construction_worker: only publish when version changes
techouse May 14, 2023
983bf0d
:construction_worker: only publish when version changes
techouse May 14, 2023
ab121f5
:construction_worker: only publish when version changes
techouse May 14, 2023
806d0ae
:construction_worker: only publish when version changes
techouse May 14, 2023
65c5101
:construction_worker: only publish when version changes
techouse May 14, 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
77 changes: 50 additions & 27 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Publish packages

on:
push:
pull_request:
branches:
- master
defaults:
Expand All @@ -12,48 +12,71 @@ env:
permissions: read-all

jobs:
publish_chopper:
name: "Publish chopper"
get_base_version:
name: "Get base version"
runs-on: ubuntu-latest
strategy:
matrix:
package: [ chopper, chopper_generator, chopper_built_value ]
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 }}
steps:
- uses: dart-lang/setup-dart@v1
with:
sdk: stable
- id: checkout
uses: actions/checkout@v3
- id: credentials
run: |
mkdir -p $XDG_CONFIG_HOME/dart
echo '${{ secrets.CREDENTIAL_JSON }}' > "$XDG_CONFIG_HOME/dart/pub-credentials.json"
- id: publish
run: bash tool/publish.sh chopper
publish_chopper_generator:
name: "Publish chopper_generator"
runs-on: ubuntu-latest
steps:
- uses: dart-lang/setup-dart@v1
with:
sdk: stable
- id: checkout
uses: actions/checkout@v3
- id: credentials
ref: ${{ github.event.pull_request.base.ref }}
- name: Load base version
id: load_base_version
run: |
mkdir -p $XDG_CONFIG_HOME/dart
echo '${{ secrets.CREDENTIAL_JSON }}' > "$XDG_CONFIG_HOME/dart/pub-credentials.json"
- id: publish
run: bash tool/publish.sh chopper_generator
publish_chopper_built_value:
name: "Publish chopper_built_value"
set -e
echo "BASE_VERSION_${{ matrix.package }}=$(awk '/^version: / {print $2}' ${{ matrix.package }}/pubspec.yaml)" >> $GITHUB_OUTPUT
publish:
name: "Publish"
needs: get_base_version
runs-on: ubuntu-latest
strategy:
matrix:
package: [ chopper, chopper_generator, chopper_built_value ]
steps:
- uses: dart-lang/setup-dart@v1
with:
sdk: stable
- id: checkout
uses: actions/checkout@v3
- id: credentials
- 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
- name: Set up pub credentials
id: credentials
if: ${{ env.IS_VERSION_GREATER == 1 }}
run: |
set -e
mkdir -p $XDG_CONFIG_HOME/dart
echo '${{ secrets.CREDENTIAL_JSON }}' > "$XDG_CONFIG_HOME/dart/pub-credentials.json"
- id: publish
run: bash tool/publish.sh chopper_built_value
- name: Publish
id: publish
if: ${{ env.IS_VERSION_GREATER == 1 }}
run: bash tool/publish.sh ${{ matrix.package }}
- name: Skip publish
id: skip_publish
if: ${{ env.IS_VERSION_GREATER == 0 }}
run: echo "Skipping publish for ${{ matrix.package }} because the version is not greater than the one on pub.dev"
64 changes: 46 additions & 18 deletions .github/workflows/publish_dry_run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,64 @@ env:
permissions: read-all

jobs:
publish_chopper:
name: "Publish chopper (dry run)"
get_base_version:
name: "Get base version"
runs-on: ubuntu-latest
strategy:
matrix:
package: [ chopper, chopper_generator, chopper_built_value ]
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 }}
steps:
- uses: dart-lang/setup-dart@v1
with:
sdk: stable
- id: checkout
uses: actions/checkout@v3
- id: publish_dry_run
run: bash tool/publish.sh chopper --dry-run
publish_chopper_generator:
name: "Publish chopper_generator (dry run)"
runs-on: ubuntu-latest
steps:
- uses: dart-lang/setup-dart@v1
with:
sdk: stable
- id: checkout
uses: actions/checkout@v3
- id: publish_dry_run
run: bash tool/publish.sh chopper_generator --dry-run
publish_chopper_built_value:
name: "Publish chopper_built_value (dry run)"
ref: ${{ github.event.pull_request.base.ref }}
- 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
publish_dry_run:
name: "Publish DRY RUN"
needs: get_base_version
runs-on: ubuntu-latest
strategy:
matrix:
package: [ chopper, chopper_generator, chopper_built_value ]
steps:
- uses: dart-lang/setup-dart@v1
with:
sdk: stable
- id: checkout
uses: actions/checkout@v3
- id: publish_dry_run
run: bash tool/publish.sh chopper_built_value --dry-run
- 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
- name: Publish (dry run)
id: publish_dry_run
if: ${{ env.IS_VERSION_GREATER == 1 }}
run: bash tool/publish.sh ${{ matrix.package }} --dry-run
- name: Skip publish (dry run)
id: skip_publish_dry_run
if: ${{ env.IS_VERSION_GREATER == 0 }}
run: echo "Skipping publish (dry run) for ${{ matrix.package }} because the version is not greater than the one on pub.dev"
38 changes: 38 additions & 0 deletions tool/compare_versions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'dart:io' show exitCode, stderr, stdout;
import 'package:cli_script/cli_script.dart' show wrapMain;
import 'package:pub_semver/pub_semver.dart' show Version;

void main(List<String> args) {
wrapMain(() {
exitCode = 0;

if (args.length != 2) {
stderr.write(
'Please provide two arguments!\n\nExample usage:\ndart run compare_versions.dart 2.0.0+1 1.9.0+5\n',
);
exitCode = 1;
return;
}

late final Version v1;
late final Version v2;

try {
v1 = Version.parse(args[0]);
} on FormatException catch (e) {
stderr.write('Error parsing version 1: ${e.message}');
exitCode = 1;
return;
}

try {
v2 = Version.parse(args[1]);
} on FormatException catch (e) {
stderr.write('Error parsing version 2: ${e.message}');
exitCode = 1;
return;
}

stdout.write(v1 > v2 ? 1 : 0);
});
}
12 changes: 12 additions & 0 deletions tool/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: compare_versions

publish_to: 'none'

version: 1.0.0

environment:
sdk: ">=2.17.0 <4.0.0"

dependencies:
cli_script: ^0.3.1
pub_semver: ^2.1.4