Skip to content

Commit

Permalink
Added deployment type to checks
Browse files Browse the repository at this point in the history
  • Loading branch information
leoafarias committed Feb 14, 2024
1 parent f959cf2 commit cdf5ef3
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 38 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/deploy_homebrew.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ jobs:
runs-on: macos-latest
env:
PUB_CREDENTIALS: ${{ secrets.PUB_CREDENTIALS }}
GITHUB_TOKEN: ${{ secrets.HOMEBREW_FVM_GH_TOKEN }}
GITHUB_BEARER_TOKEN: ${{ secrets.HOMEBREW_FVM_GH_TOKEN }}
steps:
- name: Checkout
Expand All @@ -18,6 +17,9 @@ jobs:
- name: Prepare environment
uses: ./.github/actions/prepare

- name: Build version and env
run: dart run grinder build-version --deploy-type=brew

- name: Deploy homebrew
run: dart run grinder pkg-homebrew-update

Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/deploy_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: macos-latest
env:
PUB_CREDENTIALS: ${{ secrets.PUB_CREDENTIALS }}
GITHUB_TOKEN: ${{ secrets.HOMEBREW_FVM_GH_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_BEARER_TOKEN: ${{ secrets.HOMEBREW_FVM_GH_TOKEN }}

steps:
Expand All @@ -19,5 +19,9 @@ jobs:
- name: Prepare environment
uses: ./.github/actions/prepare

- name: Build version and env
run: dart run grinder build-version --deploy-type=brew

- name: Deploy Github Mac
run: dart run grinder pkg-github-macos
run: dart run grinder pkg-github-macos

3 changes: 3 additions & 0 deletions .github/workflows/deploy_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:

- name: Prepare environment
uses: ./.github/actions/prepare

- name: Build version and env
run: dart run grinder build-version --deploy-type=chocolatey

- name: Deploy Github Windows
run: dart run grinder pkg-github-windows
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ jobs:

- name: Prepare environment
uses: ./.github/actions/prepare

- name: Build version and env
run: dart run grinder build-version --deploy-type=chocolatey

- name: Deploy Github Windows
run: dart run grinder pkg-github-windows
Expand All @@ -61,15 +64,19 @@ jobs:
runs-on: macos-latest
needs: release
env:
PUB_CREDENTIALS: ${{ secrets.PUB_CREDENTIALS }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_BEARER_TOKEN: ${{ secrets.HOMEBREW_FVM_GH_TOKEN }}

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

- name: Prepare environment
uses: ./.github/actions/prepare

- name: Build version and env
run: dart run grinder build-version --deploy-type=brew

- name: Deploy Github Mac
run: dart run grinder pkg-github-macos

Expand Down
73 changes: 46 additions & 27 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
description: "Dart SDK version"
type: string
required: false
# Version that is been tested with
default: "3.1.3"

pull_request:
Expand All @@ -21,14 +22,10 @@ concurrency:

jobs:
test:
name: Test on ${{ matrix.os }}
name: Test
timeout-minutes: 30
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

Expand All @@ -37,35 +34,57 @@ jobs:
with:
sdk-version: ${{ github.event.inputs.sdk-version }}

# - name: Install DCM
# uses: CQLabs/setup-dcm@v1
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}

# - name: Run DCM
# uses: CQLabs/dcm-action@v1
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# folders: lib
- uses: invertase/github-action-dart-analyzer@v1
with:
fatal-infos: false


- name: Tests
uses: ./.github/actions/test
if: matrix.os != 'ubuntu-latest'

- name: Install DCM
uses: CQLabs/setup-dcm@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Run DCM
uses: CQLabs/dcm-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
ci_key: oss
email: oss
folders: .
fatal_style: true
fatal_performance: true
fatal_warnings: true

- name: Install lcov
run: sudo apt-get install lcov
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get install lcov

- name: Run tests
uses: ./.github/actions/test
if: matrix.os == 'ubuntu-latest'
with:
with-coverage: 'true'

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
if: matrix.os == 'ubuntu-latest'
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}


test-os:
name: Test on ${{ matrix.os }}
needs: test
timeout-minutes: 30
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, windows-latest]

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

- name: Prepare environment
uses: ./.github/actions/prepare
with:
sdk-version: ${{ github.event.inputs.sdk-version }}

- name: Tests
uses: ./.github/actions/test
1 change: 0 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ include: package:lints/recommended.yaml
analyzer:
exclude:
- "**/*.g.dart"
- "tool/**"
# For lint rules and documentation, see http://dart-lang.github.io/linter/lints.
# Uncomment to specify additional rules.
linter:
Expand Down
34 changes: 30 additions & 4 deletions lib/src/commands/update_command.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import 'dart:io';

import 'package:args/command_runner.dart';
import 'package:fvm/constants.dart';
import 'package:fvm/src/services/logger_service.dart';
import 'package:fvm/src/version.g.dart';
import 'package:mason_logger/mason_logger.dart';
import 'package:pub_updater/pub_updater.dart';

import '../../constants.dart';

Check notice on line 7 in lib/src/commands/update_command.dart

View workflow job for this annotation

GitHub Actions / DCM report

lib/src/commands/update_command.dart#L7

Avoid importing entrypoint exports. Try importing the source file directly instead of importing the re-export.
import '../services/logger_service.dart';
import '../version.g.dart';

class UpdateCommand extends Command<int> {
static const String commandName = 'update';

Expand All @@ -24,16 +25,39 @@ class UpdateCommand extends Command<int> {
} catch (error) {
updateCheckProgress.fail();
logger.err('$error');

return ExitCode.software.code;
}
updateCheckProgress.complete('Checked for updates');

final isUpToDate = packageVersion == latestVersion;
if (isUpToDate) {
logger.info('CLI is already at the latest version.');
logger.success('You are already using the latest version.');

return ExitCode.success.code;
}

switch (deployType) {
case 'brew':
final upgradeCommand = cyan.wrap('brew upgrade $kPackageName');
logger
..info('')
..info('This version was installed using brew.')
..notice('Please update using: $upgradeCommand');

Check warning on line 46 in lib/src/commands/update_command.dart

View workflow job for this annotation

GitHub Actions / DCM report

lib/src/commands/update_command.dart#L46

This interpolation is potentially nullable. Try checking for a null value first.

return ExitCode.success.code;
case 'chocolatey':
final upgradeCommand = cyan.wrap('choco upgrade $kPackageName');
logger
..info('')
..info('This version was installed using chocolatey.')
..notice('Please update using: $upgradeCommand');

Check warning on line 54 in lib/src/commands/update_command.dart

View workflow job for this annotation

GitHub Actions / DCM report

lib/src/commands/update_command.dart#L54

This interpolation is potentially nullable. Try checking for a null value first.

return ExitCode.success.code;
default:
break;
}

final updateProgress = logger.progress('Updating to $latestVersion');

late final ProcessResult result;
Expand All @@ -45,12 +69,14 @@ class UpdateCommand extends Command<int> {
} catch (error) {
updateProgress.fail();
logger.err('$error');

return ExitCode.software.code;
}

if (result.exitCode != ExitCode.success.code) {
updateProgress.fail();
logger.err('Error updating CLI: ${result.stderr}');

return ExitCode.software.code;
}

Expand Down
1 change: 1 addition & 0 deletions lib/src/version.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion tool/grind.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ void main(List<String> args) {
pkg.githubUser.value = owner;
pkg.githubRepo.value = 'leoafarias/fvm';
pkg.homebrewRepo.value = 'leoafarias/homebrew-fvm';
pkg.githubBearerToken.value = Platform.environment['GITHUB_TOKEN'];
pkg.githubBearerToken.value = Platform.environment['GITHUB_BEARER_TOKEN'];
pkg.homebrewCreateVersionedFormula.value = true;

pkg.addAllTasks();
addTask(homebrewTask());
Expand All @@ -33,6 +34,7 @@ void main(List<String> args) {
Future<void> buildVersion() async {
final args = context.invocation.arguments;
final versionArg = args.getOption('version');
final deployTypeArg = args.getOption('deploy-type');

final pubspec = await PubSpec.load(Directory.current);
Version? version = pubspec.version;
Expand All @@ -54,9 +56,14 @@ Future<void> buildVersion() async {
versionFile.createSync(recursive: true);
}

if (!['pub', 'brew', 'chocolatey'].contains(deployTypeArg)) {
throw Exception('Invalid deploy environment: $deployTypeArg');

Check warning on line 60 in tool/grind.dart

View workflow job for this annotation

GitHub Actions / DCM report

tool/grind.dart#L60

This interpolation is potentially nullable. Try checking for a null value first.
}

// Add comment on top of the const that this file is generated by this command
String fileContent = '// GENERATED CODE - DO NOT MODIFY BY HAND\n\n';
fileContent += "const packageVersion = '$version';\n";

Check warning on line 65 in tool/grind.dart

View workflow job for this annotation

GitHub Actions / DCM report

tool/grind.dart#L65

This interpolation is potentially nullable. Try checking for a null value first.
fileContent += "const deployType = '$deployTypeArg';\n";

Check warning on line 66 in tool/grind.dart

View workflow job for this annotation

GitHub Actions / DCM report

tool/grind.dart#L66

This interpolation is potentially nullable. Try checking for a null value first.

versionFile.writeAsStringSync(fileContent);

Expand Down

0 comments on commit cdf5ef3

Please sign in to comment.