Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
63 changes: 63 additions & 0 deletions .github/actions/setup/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Setup
description: Sets up the Dart environment

inputs:
dart-version:
description: "The version of Dart to use"
required: false
default: "3.7.0"
pub-cache:
description: "The name of the pub cache variable"
required: false
default: app

runs:
using: composite
steps:
- name: 📦 Checkout the repo
uses: actions/checkout@v4

- name: 🔢 Set up version from tags
id: set-version
if: startsWith(github.ref, 'refs/tags')
shell: bash
run: |
BASE_VERSION="${GITHUB_REF#refs/tags/v}"
UNIXTIME=$(date +%s)
VERSION="${BASE_VERSION}+${UNIXTIME}"
echo "VERSION=$VERSION" >> $GITHUB_ENV
sed -i "s/^version: .*/version: ${VERSION}/" pubspec.yaml
echo "Version set to $VERSION"

- name: 🚂 Setup Dart
uses: dart-lang/setup-dart@v1
with:
sdk: "${{ inputs.dart-version }}"

- name: 📤 Restore Pub modules
id: cache-pub-restore
uses: actions/cache/restore@v4
with:
path: |
/home/runner/.pub-cache
key: ${{ runner.os }}-pub-${{ inputs.pub-cache }}-${{ hashFiles('pubspec.lock') }}

- name: 👷 Install Dependencies
shell: bash
run: |
echo /home/runner/.pub-cache/bin >> $GITHUB_PATH
dart pub get

#- name: ⏲️ Run build runner
# shell: bash
# run: |
# dart run build_runner build --delete-conflicting-outputs --release

- name: 📥 Save Pub modules
id: cache-pub-save
if: steps.cache-pub-restore.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: |
/home/runner/.pub-cache
key: ${{ steps.cache-pub-restore.outputs.cache-primary-key }}
10 changes: 10 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
enable-beta-ecosystems: true
updates:
- directory: "/"
open-pull-requests-limit: 5
package-ecosystem: "pub"
rebase-strategy: auto
schedule:
interval: "monthly"
timezone: "UTC"
108 changes: 69 additions & 39 deletions .github/workflows/checkout.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,76 +4,106 @@ on:
workflow_dispatch:
push:
branches:
- "main"
- "master"
- "develop"
- "feature/**"
- "bugfix/**"
- "hotfix/**"
- "support/**"
paths:
- "lib/**.dart"
- "test/**.dart"
- "example/**.dart"
- "pubspec.yaml"
pull_request:
branches:
- "main"
- "master"
- "dev"
- "develop"
- "feature/**"
- "bugfix/**"
- "hotfix/**"
- "support/**"
paths:
- "pubspec.yaml"
- ".github/**.yaml"
- ".github/**.yml"
- "bin/**.dart"
- "lib/**.dart"
- "test/**.dart"
- "example/**.dart"
- "pubspec.yaml"

jobs:
checkout:
name: "Checkout"
name: "🧪 Check code with analysis, format, and tests"
runs-on: ubuntu-latest
env:
threshold: 5
defaults:
run:
working-directory: ./
container:
image: dart:beta
timeout-minutes: 10
steps:
- name: 🚂 Get latest code
uses: actions/checkout@v3

- name: 🚃 Cache pub modules
uses: actions/cache@v2
env:
cache-name: cache-package
- name: 📦 Get the .github actions
uses: actions/checkout@v4
with:
path: |
$PWD/.pub_cache/
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/pubspec.yaml') }}
fetch-depth: 2
sparse-checkout: |
.github

- name: 🗄️ Export pub cache directory
run: export PUB_CACHE=$PWD/.pub_cache/
- name: 🚂 Setup Dart and dependencies
uses: ./.github/actions/setup
with:
dart-version: 3.7.0

- name: 👷 Install Dependencies
- name: 🚦 Check code format
id: check-format
timeout-minutes: 1
run: |
dart pub get

- name: 🔎 Check format
timeout-minutes: 1
run: dart format --set-exit-if-changed -l 80 -o none lib/
find lib test -name "*.dart" ! -name "*.*.dart" -print0 | xargs -0 dart format --set-exit-if-changed --line-length 80 -o none bin/ lib/ test/

- name: 📈 Check analyzer
id: check-analyzer
timeout-minutes: 1
run: dart analyze --fatal-infos --fatal-warnings lib/
run: dart analyze --fatal-infos --fatal-warnings bin/ lib/ test/

- name: 🧪 Run tests
timeout-minutes: 2
timeout-minutes: 5
run: |
dart run coverage:test_with_coverage -fb -o coverage -- \
--concurrency=6 --platform vm --coverage=./coverage --reporter=expanded test/pubspec_generator_test.dart
dart pub global activate coverage
dart pub global run coverage:test_with_coverage -fb -o coverage -- \
--platform=vm --compiler=kernel --coverage=coverage \
--reporter=github --file-reporter=json:reports/tests.json \
--timeout=10m --concurrency=12 --color \
test/pubspec_generator_test.dart

- name: 📥 Upload coverage to Codecov
timeout-minutes: 1
uses: codecov/codecov-action@v3
#- name: 🎁 Setup LCOV
# timeout-minutes: 5
# uses: hrishikesh-kadam/setup-lcov@v1

#- name: 🔍 Check coverage
# id: check-coverage
# timeout-minutes: 1
# run: |
# lcov --list coverage/lcov.info
# THRESHOLD=${{ env.threshold }}
# COVERAGE=$(lcov --summary coverage/lcov.info | grep -i 'lines\|Total:' | tail -n 1 | awk '{print $2}' | sed 's/%//')
# echo "Coverage is $COVERAGE%"
# echo $COVERAGE | awk '{if ($1 < 50) exit 1}'

#- name: 🔍 Report code coverage
# uses: zgosalvez/github-actions-report-lcov@v4
# with:
# coverage-files: coverage/lcov.info
# minimum-coverage: ${{ env.threshold }}
# artifact-name: code-coverage-report
# github-token: ${{ secrets.GITHUB_TOKEN }}
# working-directory: ./
# update-comment: true

#- name: 📥 Upload coverage report
# timeout-minutes: 5
# if: ${{ github.actor != 'dependabot[bot]' }}
# uses: codecov/codecov-action@v2
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# files: ./coverage/lcov.info

- name: 📥 Upload test report
uses: actions/upload-artifact@v4
if: (success() || failure()) && ${{ github.actor != 'dependabot[bot]' }}
with:
name: test-results
path: reports/tests.json
28 changes: 28 additions & 0 deletions .github/workflows/tests-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "Tests Report"

on:
workflow_run:
workflows: ["Checkout"]
types:
- completed

permissions:
contents: read
actions: read
checks: write

jobs:
report:
name: "🚛 Tests report"
runs-on: ubuntu-latest
timeout-minutes: 10
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Test report
uses: dorny/test-reporter@v1
with:
artifact: test-results
name: Test Report
path: "**/tests.json"
reporter: flutter-json
fail-on-error: false
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"dart-code.dart-code"
]
}
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Example",
"request": "launch",
"type": "dart",
"program": "tool/runner.dart",
}
]
}
44 changes: 44 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"[dart]": {
"editor.selectionHighlight": false,
"editor.suggest.snippetsPreventQuickSuggestions": false,
"editor.suggestSelection": "first",
"editor.tabCompletion": "onlySnippets",
"editor.wordBasedSuggestions": false,
"editor.rulers": [
80
],
"editor.defaultFormatter": "Dart-Code.dart-code",
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
//"editor.formatOnType" : true,
"editor.insertSpaces": true
},
"dart.lineLength": 80,
"dart.doNotFormat": [
"**.g.dart",
"**.mocks.dart"
],
"search.exclude": {
".dart_tool": true,
"coverage": true,
"build": true
},
"files.watcherExclude": {
".dart_tool": true,
"coverage": true,
"build": true
},
"debug.openDebug": "openOnDebugBreak",
"explorer.fileNesting.enabled": true,
"explorer.fileNesting.expand": false,
"explorer.fileNesting.patterns": {
"pubspec.yaml": ".packages, .metadata, .packages, pubspec.lock, *.yaml",
".gitignore": ".gitattributes, .gitmodules, .gitmessage, .mailmap, .git-blame*, .dockerignore",
"readme.*": "authors, backers.md, changelog*, citation*, code_of_conduct.md, codeowners, contributing.md, contributors, copying, credits, governance.md, history.md, license*, maintainers, readme*, security.md, sponsors.md",
"*.dart": "$(capture).g.dart, $(capture).i.dart, $(capture).stub.dart, $(capture).web.dart, $(capture).html.dart, $(capture).js.dart, $(capture).io.dart, $(capture).base.dart"
},
"files.associations": {
"*.drift": "sql"
}
}
17 changes: 17 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Dependencies",
"type": "shell",
"command": [
"dart pub get"
],
"group": {
"kind": "none",
"isDefault": true
},
"problemMatcher": []
}
]
}
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 4.2.0

- **ADDED**: Command line utility to generate pubspec.dart from a pubspec.yaml file.

## 4.1.0-pre.1 - 2023-10-24

# Added

- Disable timestamp generation option

## 4.0.0 - 2023-07-03

### Changed
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ Pubspec Generator is a Dart library that auto-generates a class containing the i

**Continually updated:** The generated class updates as your pubspec.yaml changes, so your application's metadata remains current at all times.

## Command line utility

You can use the command line utility to generate a `pubspec.dart` file from a `pubspec.yaml` file.
This is useful for quickly generating the Dart class without needing to set up a full build environment.

```sh
dart pub global activate pubspec_generator
dart pub global run pubspec_generator:generate --input pubspec.yaml --output lib/src/pubspec.yaml.g.dart
```

## Installation

First, add pubspec_info_codegen to your `pubspec.yaml`:
Expand Down
Loading