diff --git a/.github/workflows/analyze.yaml b/.github/workflows/analyze.yaml new file mode 100644 index 00000000..51e9e8ae --- /dev/null +++ b/.github/workflows/analyze.yaml @@ -0,0 +1,54 @@ +name: Analyze + +on: + push: + branches: + - main + pull_request: + workflow_call: + inputs: + artifact: + description: Artifact to analyze instead of checking out the repository. + required: false + type: string + default: '' + +concurrency: + group: ${{ github.repository == 'vrchatapi/vrchatapi-dart' && format('{0}-{1}', github.workflow, github.ref) || format('analyze-{0}', github.run_id) }} + cancel-in-progress: true + +jobs: + analyze: + runs-on: ubuntu-latest + strategy: + matrix: + package: [vrchat_dart, vrchat_dart_generated] + defaults: + run: + working-directory: ${{ matrix.package }} + steps: + - if: ${{ inputs.artifact }} + uses: actions/download-artifact@v8 + with: + name: ${{ inputs.artifact }} + - if: ${{ !inputs.artifact }} + uses: actions/checkout@v7 + - uses: dart-lang/setup-dart@v1.8.0 + - name: Pub cache + uses: actions/cache@v6 + env: + cache-name: ${{ matrix.package }} + with: + path: ${{ env.PUB_CACHE }} + key: ${{ env.cache-name }}-${{ hashFiles('**/pubspec.lock') }} + restore-keys: ${{ env.cache-name }}- + - run: | + dart pub get + if [ -d example_flutter ]; then + dart pub get --directory=example_flutter + fi + - run: dart analyze --fatal-infos + - run: dart pub publish --dry-run + - run: | + dart pub global activate pana + pana --no-warning --exit-code-threshold 0 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f5cba36c..77a64da8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,8 +1,6 @@ +name: CI + on: - push: - branches: - - '**' - pull_request: workflow_call: inputs: ref: @@ -11,8 +9,6 @@ on: type: string default: main -name: CI - jobs: generate: runs-on: ubuntu-latest @@ -21,21 +17,15 @@ jobs: with: repository: vrchatapi/vrchatapi-dart ref: ${{ inputs.ref || github.ref }} - - uses: dart-lang/setup-dart@v1.8.0 - - uses: vrchatapi/specification/.github/actions/setup-generator@main - - uses: vrchatapi/specification/.github/actions/download@main with: bundle: openapi-3.0.yaml - - run: | mkdir -p ../vrchatapi-specification/dist mv openapi-3.0.yaml ../vrchatapi-specification/dist/ - - run: ./generate.sh local - - uses: actions/upload-artifact@v7 with: name: dart-generated @@ -46,40 +36,6 @@ jobs: analyze: needs: generate - runs-on: ubuntu-latest - steps: - - uses: actions/download-artifact@v8 - with: - name: dart-generated - - - uses: dart-lang/setup-dart@v1.8.0 - - - run: dart pub get - working-directory: vrchat_dart_generated - - - run: dart analyze - working-directory: vrchat_dart_generated - - pana: - needs: generate - runs-on: ubuntu-latest - strategy: - matrix: - package: [vrchat_dart, vrchat_dart_generated] - defaults: - run: - working-directory: ${{ matrix.package }} - steps: - - uses: actions/download-artifact@v8 - with: - name: dart-generated - - - uses: dart-lang/setup-dart@v1.8.0 - - - run: dart pub get - - - run: dart pub publish --dry-run - - - run: | - dart pub global activate pana - pana --no-warning --exit-code-threshold 0 + uses: vrchatapi/vrchatapi-dart/.github/workflows/analyze.yaml@main + with: + artifact: dart-generated diff --git a/.github/workflows/generate.yml b/.github/workflows/generate.yml index cc5c497d..999682f3 100644 --- a/.github/workflows/generate.yml +++ b/.github/workflows/generate.yml @@ -4,6 +4,12 @@ on: repository_dispatch: types: [release] workflow_dispatch: + inputs: + url: + description: OpenAPI bundle URL. Release dispatches use the triggering release instead. + required: false + type: string + default: https://github.com/vrchatapi/specification/releases/download/nightly/openapi-3.0.yaml jobs: generate: @@ -24,9 +30,15 @@ jobs: restore-keys: ${{ env.cache-name }}- - uses: vrchatapi/specification/.github/actions/setup-generator@main - + - uses: vrchatapi/specification/.github/actions/download@main + with: + bundle: openapi-3.0.yaml + url: ${{ github.event_name == 'workflow_dispatch' && inputs.url || '' }} + - run: | + mkdir -p ../vrchatapi-specification/dist + mv openapi-3.0.yaml ../vrchatapi-specification/dist/ - name: Generate - run: ./generate.sh + run: ./generate.sh local - name: Check for CHANGELOG changes id: changelog diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b8b22a9b..d9abaae0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,7 +2,7 @@ name: Test on: push: branches: - - '**' + - main pull_request: concurrency: @@ -29,7 +29,7 @@ jobs: env: SECRET_FILE_CONTENT: ${{ secrets.TEST_CREDENTIALS_FILE }} run: | - echo $SECRET_FILE_CONTENT | base64 -d > vrchat_dart/example/bin/credentials.dart + echo $SECRET_FILE_CONTENT | base64 -d > vrchat_dart/example/bin/credentials.json - name: Run example run: | cd vrchat_dart/example diff --git a/vrchat_dart/.gitignore b/vrchat_dart/.gitignore index a793e3e0..821b90df 100644 --- a/vrchat_dart/.gitignore +++ b/vrchat_dart/.gitignore @@ -78,4 +78,4 @@ build/ .cookies/ # Credentials -credentials.dart \ No newline at end of file +credentials.json \ No newline at end of file diff --git a/vrchat_dart/example/bin/credentials.dart b/vrchat_dart/example/bin/credentials.dart new file mode 100644 index 00000000..fe26363d --- /dev/null +++ b/vrchat_dart/example/bin/credentials.dart @@ -0,0 +1,25 @@ +import 'package:meta/meta.dart'; + +@immutable +class Credentials { + const Credentials({ + required this.username, + required this.password, + required this.contactInfo, + required this.otpSecret, + }); + + factory Credentials.fromJson(Map json) { + return Credentials( + username: json['username'] as String, + password: json['password'] as String, + contactInfo: json['contactInfo'] as String, + otpSecret: json['otpSecret'] as String, + ); + } + + final String username; + final String password; + final String contactInfo; + final String otpSecret; +} diff --git a/vrchat_dart/example/bin/main.dart b/vrchat_dart/example/bin/main.dart index ecccd08b..0430979a 100644 --- a/vrchat_dart/example/bin/main.dart +++ b/vrchat_dart/example/bin/main.dart @@ -1,27 +1,35 @@ import 'dart:convert'; -import 'dart:io'; +import 'dart:io' as io; import 'package:otp/otp.dart'; import 'package:vrchat_dart/vrchat_dart.dart'; -/// Create the file `lib/credentials.dart` with the fields required to make -/// this file happy import 'credentials.dart'; const tupperUid = 'usr_c1644b5b-3ca4-45b4-97c6-a2a0de70d469'; void main() async { + // Create `bin/credentials.json` with username, password, contactInfo, and + // otpSecret. + final credentials = Credentials.fromJson( + jsonDecode( + await io.File.fromUri( + io.Platform.script.resolve('credentials.json'), + ).readAsString(), + ) as Map, + ); + final api = VrchatDart( userAgent: VrchatUserAgent( applicationName: 'vrchat_dart_example', version: '0.0.0', - contactInfo: Credentials.contactInfo, + contactInfo: credentials.contactInfo, ), ); final (loginSuccess, loginFailure) = await api.auth.login( - username: Credentials.username, - password: Credentials.password, + username: credentials.username, + password: credentials.password, ); if (loginSuccess == null) { @@ -44,7 +52,7 @@ void main() async { // scripts. To get around this, enable 2FA on your account and generate // codes in your script. final code = OTP.generateTOTPCodeString( - Credentials.otpSecret, + credentials.otpSecret, DateTime.timestamp().millisecondsSinceEpoch, algorithm: Algorithm.SHA1, isGoogle: true, @@ -125,7 +133,7 @@ void main() async { print(worldSuccess.data.name); // Do not start websocket streaming if this code is running in CI - if (Platform.environment.containsKey('GITHUB_ACTIONS')) return; + if (io.Platform.environment.containsKey('GITHUB_ACTIONS')) return; // Listen for updates api.streaming.vrcEventStream.listen(handleVrcEvent); diff --git a/vrchat_dart/example/pubspec.yaml b/vrchat_dart/example/pubspec.yaml index 3098bd3f..e1ae50b6 100644 --- a/vrchat_dart/example/pubspec.yaml +++ b/vrchat_dart/example/pubspec.yaml @@ -8,6 +8,7 @@ dependencies: vrchat_dart: path: ../ + meta: ^1.16.0 otp: ^3.1.3 dev_dependencies: diff --git a/vrchat_dart/example_flutter/.metadata b/vrchat_dart/example_flutter/.metadata deleted file mode 100644 index e7c10010..00000000 --- a/vrchat_dart/example_flutter/.metadata +++ /dev/null @@ -1,45 +0,0 @@ -# This file tracks properties of this Flutter project. -# Used by Flutter tool to assess capabilities and perform upgrades etc. -# -# This file should be version controlled. - -version: - revision: 85684f9300908116a78138ea4c6036c35c9a1236 - channel: stable - -project_type: app - -# Tracks metadata for the flutter migrate command -migration: - platforms: - - platform: root - create_revision: 85684f9300908116a78138ea4c6036c35c9a1236 - base_revision: 85684f9300908116a78138ea4c6036c35c9a1236 - - platform: android - create_revision: 85684f9300908116a78138ea4c6036c35c9a1236 - base_revision: 85684f9300908116a78138ea4c6036c35c9a1236 - - platform: ios - create_revision: 85684f9300908116a78138ea4c6036c35c9a1236 - base_revision: 85684f9300908116a78138ea4c6036c35c9a1236 - - platform: linux - create_revision: 85684f9300908116a78138ea4c6036c35c9a1236 - base_revision: 85684f9300908116a78138ea4c6036c35c9a1236 - - platform: macos - create_revision: 85684f9300908116a78138ea4c6036c35c9a1236 - base_revision: 85684f9300908116a78138ea4c6036c35c9a1236 - - platform: web - create_revision: 85684f9300908116a78138ea4c6036c35c9a1236 - base_revision: 85684f9300908116a78138ea4c6036c35c9a1236 - - platform: windows - create_revision: 85684f9300908116a78138ea4c6036c35c9a1236 - base_revision: 85684f9300908116a78138ea4c6036c35c9a1236 - - # User provided section - - # List of Local paths (relative to this file) that should be - # ignored by the migrate tool. - # - # Files that are not part of the templates will be ignored by default. - unmanaged_files: - - 'lib/main.dart' - - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/vrchat_dart/example_flutter/analysis_options.yaml b/vrchat_dart/example_flutter/analysis_options.yaml index 809fe36b..37089f53 100644 --- a/vrchat_dart/example_flutter/analysis_options.yaml +++ b/vrchat_dart/example_flutter/analysis_options.yaml @@ -1,5 +1 @@ include: package:rexios_lints/flutter/core_extra.yaml - -analyzer: - exclude: - - build/** diff --git a/vrchat_dart/example_flutter/lib/vrc_api_container_impl_native.dart b/vrchat_dart/example_flutter/lib/vrc_api_container_impl_native.dart index 92ede969..9bbd323b 100644 --- a/vrchat_dart/example_flutter/lib/vrc_api_container_impl_native.dart +++ b/vrchat_dart/example_flutter/lib/vrc_api_container_impl_native.dart @@ -1,5 +1,3 @@ -import 'package:package_info_plus/package_info_plus.dart'; -import 'package:path_provider/path_provider.dart'; import 'package:vrchat_dart/vrchat_dart.dart'; import 'package:vrchat_dart_example_flutter/vrc_api_container_impl_base.dart'; @@ -7,14 +5,15 @@ import 'package:vrchat_dart_example_flutter/vrc_api_container_impl_base.dart'; class VrcApiContainerImpl extends VrcApiContainerImplBase { @override Future create() async { - final packageInfo = await PackageInfo.fromPlatform(); - final appDocDir = await getApplicationDocumentsDirectory(); - final appDocPath = appDocDir.path; + // In a real app, use package_info_plus. + const version = '0.0.0'; + // In a real app, use path_provider. + const appDocPath = 'path/to/application/documents'; return VrchatDart( - userAgent: VrchatUserAgent( + userAgent: const VrchatUserAgent( applicationName: 'vrchat_dart_example', - version: packageInfo.version, + version: version, contactInfo: 'TODO', ), cookiePath: appDocPath, diff --git a/vrchat_dart/example_flutter/lib/vrc_api_container_impl_web.dart b/vrchat_dart/example_flutter/lib/vrc_api_container_impl_web.dart index 0d05a1d9..afabd231 100644 --- a/vrchat_dart/example_flutter/lib/vrc_api_container_impl_web.dart +++ b/vrchat_dart/example_flutter/lib/vrc_api_container_impl_web.dart @@ -1,4 +1,3 @@ -import 'package:package_info_plus/package_info_plus.dart'; import 'package:vrchat_dart/vrchat_dart.dart'; import 'package:vrchat_dart_example_flutter/vrc_api_container_impl_base.dart'; @@ -6,11 +5,12 @@ import 'package:vrchat_dart_example_flutter/vrc_api_container_impl_base.dart'; class VrcApiContainerImpl extends VrcApiContainerImplBase { @override Future create() async { - final packageInfo = await PackageInfo.fromPlatform(); + // In a real app, use package_info_plus. + const version = '0.0.0'; return VrchatDart( - userAgent: VrchatUserAgent( + userAgent: const VrchatUserAgent( applicationName: 'vrchat_dart_example', - version: packageInfo.version, + version: version, contactInfo: 'TODO', ), // See nginx.conf for an example nginx configuration diff --git a/vrchat_dart/example_flutter/pubspec.yaml b/vrchat_dart/example_flutter/pubspec.yaml index 778996d4..e2ebc935 100644 --- a/vrchat_dart/example_flutter/pubspec.yaml +++ b/vrchat_dart/example_flutter/pubspec.yaml @@ -5,15 +5,9 @@ environment: sdk: ^3.0.0 dependencies: - flutter: - sdk: flutter - vrchat_dart: path: ../ - path_provider: ^2.0.11 - package_info_plus: ^10.2.1 - dev_dependencies: rexios_lints: ^19.0.0