-
Notifications
You must be signed in to change notification settings - Fork 6
/
auto_publish_tweak.dart
61 lines (49 loc) · 1.73 KB
/
auto_publish_tweak.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:io';
import '../exact_file_tweak.dart';
import '../utils.dart';
final _instance = AutoPublishTweak._();
class AutoPublishTweak extends ExactFileTweak {
factory AutoPublishTweak() => _instance;
AutoPublishTweak._()
: super(
id: 'auto-publish',
description:
'configure a github action to enable package auto-publishing',
filePath: '.github/workflows/publish.yaml',
);
@override
bool shouldRunByDefault(Directory checkout, String repoSlug) =>
monoRepo(checkout, repoSlug);
@override
String expectedContent(Directory checkout, String repoSlug) {
final org = repoSlug.split('/').first;
final branch = gitDefaultBranch(checkout) ?? 'main';
final glob = singlePackageRepo(checkout)
? "'v[0-9]+.[0-9]+.[0-9]+'"
: "'[A-z]+-v[0-9]+.[0-9]+.[0-9]+'";
// Substitute for the github org, default branch, and glob pattern values.
return publishContents
.replaceAll('{org}', org)
.replaceAll('{branch}', branch)
.replaceAll('{glob}', glob);
}
}
const publishContents = r'''
# A CI configuration to auto-publish pub packages.
name: Publish
on:
pull_request:
branches: [ {branch} ]
push:
tags: [ {glob} ]
jobs:
publish:
if: ${{ github.repository_owner == '{org}' }}
uses: dart-lang/ecosystem/.github/workflows/publish.yaml@main
permissions:
id-token: write # Required for authentication using OIDC
pull-requests: write # Required for writing the pull request note
''';