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

GH Actions work #12

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
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
43 changes: 43 additions & 0 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Dart CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: dart-lang/setup-dart@v1
with:
sdk: main

- name: Install dependencies
run: dart pub get

- name: Check format
run: dart format --output=none --set-exit-if-changed -l 80 lib

- name: Analyze
run: dart analyze lib

- name: Run tests
run: dart test --coverage coverage --reporter=github

- name: Coverage
run: dart run coverage:format_coverage -l -i ./coverage/test/due_date_test.dart.vm.json -o ./coverage/lcov.info

- name: Upload coverage to codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true # optional (default = false)
verbose: true # optional (default = false)
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
38 changes: 38 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Update Docs

on:
push:
branches:
- stable
paths:
- 'docs/api/**'
pull_request:
branches:
- stable
paths:
- 'docs/api/**'

jobs:
update-docs:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install git-filter-repo
run: sudo apt-get install -y git-filter-repo

- name: Switch to gh-pages and replace contents
run: |
git checkout gh-pages
git rm -r -f .
git checkout HEAD -- docs/api
mv docs/api/* .
git add .
git commit -m "Update gh-pages" || echo "No changes to commit"
git push

- name: Filter repo
run: |
git filter-repo --path docs/api
120 changes: 120 additions & 0 deletions .github/workflows/version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: Update Version

on:
push:
branches:
- stable
pull_request:
branches:
- stable

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Dart
uses: dart-lang/setup-dart@v1

- name: Validate files
run: |
# Extract version from pubspec.yaml
version=$(grep 'version:' pubspec.yaml | cut -d ' ' -f 2)

# Get the version from the last commit on stable (if it exists)
git fetch origin stable:stable
last_version=$(git show stable:pubspec.yaml | grep 'version:' | cut -d ' ' -f 2)

# Check if the versions are different
if [ "$version" != "$last_version" ]; then
echo "Version has been updated to $version"
else
echo "Version has not been updated"
exit 1
fi

# Check if README.md and CHANGELOG.md contain the new version number
if grep -q "$version" README.md && grep -q "$version" CHANGELOG.md; then
echo "Version number found in README.md and CHANGELOG.md"
else
echo "Version number not found in README.md or CHANGELOG.md"
exit 1
fi

- name: Delete docs directory
run: rm -rf docs/*

- name: Generate docs
run: dart doc

- name: Commit changes
run: |
git add .
git commit -m "Update docs" || echo "No changes to commit"

- name: Push changes
run: git push

- name: Setup reviewdog
uses: reviewdog/action-setup@v1
with:
reviewdog_version: latest

- name: Generate tag message
id: generate_tag_message
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION_NUMBER=$(grep 'version:' pubspec.yaml | sed 's/version: //g')
LAST_VERSION=$(git describe --abbrev=0 --tags `git rev-list --tags --skip=1 --max-count=1`)
COMMITS=$(curl -s -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/${{ github.repository }}/compare/$LAST_VERSION...$VERSION_NUMBER)

WHATS_CHANGED=""
NEW_CONTRIBUTORS=""
CONTRIBUTORS=()

for row in $(echo "${COMMITS}" | jq -r '.commits[] | @base64'); do
_jq() {
echo ${row} | base64 --decode | jq -r ${1}
}

COMMIT_SHA=$(_jq '.sha')
COMMIT_MESSAGE=$(_jq '.commit.message')
AUTHOR_USERNAME=$(_jq '.author.login')
PR_NUMBER=$(curl -s -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/${{ github.repository }}/commits/$COMMIT_SHA/pulls | jq -r '.[0].number')

WHATS_CHANGED+="$COMMIT_MESSAGE by @$AUTHOR_USERNAME in #$PR_NUMBER\n"

if [[ ! " ${CONTRIBUTORS[@]} " =~ " ${AUTHOR_USERNAME} " ]]; then
CONTRIBUTORS+=("$AUTHOR_USERNAME")
NEW_CONTRIBUTORS+="@$AUTHOR_USERNAME made their first contribution in #$PR_NUMBER\n"
fi
done

DESCRIPTION="What's Changed\n$WHATS_CHANGED\nNew Contributors\n$NEW_CONTRIBUTORS\nFull Changelog: $LAST_VERSION...$VERSION_NUMBER"
echo "::set-output name=description::$DESCRIPTION"

- name: Review tag message
run: |
echo "${{ steps.generate_tag_message.outputs.description }}" | reviewdog -f=diff -diff="git diff" -reporter=github-pr-review

- name: Create tag with version number
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git tag -a $VERSION_NUMBER -m "${{ steps.generate_tag_message.outputs.description }}"
git push origin $VERSION_NUMBER

- name: Create draft release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.generate_tag_message.outputs.version_number }}
release_name: Release ${{ steps.generate_tag_message.outputs.version_number }}
body: ${{ steps.generate_tag_message.outputs.description }}
draft: true
83 changes: 83 additions & 0 deletions .hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/sh

echo "Running pre-commit checks..."

if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=$(git hash-object -t tree /dev/null)
fi

# If you want to allow non-ASCII filenames set this variable to true.
allownonascii=$(git config --type=bool hooks.allownonascii)

# Redirect output to stderr.
exec 1>&2

# Cross platform projects tend to avoid non-ASCII filenames; prevent
# them from being added to the repository. We exploit the fact that the
# printable range starts at the space character and ends with tilde.
if [ "$allownonascii" != "true" ] &&
# Note that the use of brackets around a tr range is ok here, (it's
# even required, for portability to Solaris 10's /usr/bin/tr), since
# the square bracket bytes happen to fall in the designated range.
test $(git diff --cached --name-only --diff-filter=A -z $against |
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
then
cat <<\EOF
Error: Attempt to add a non-ASCII file name.

This can cause problems if you want to work with people on other platforms.

To be portable it is advisable to rename the file.

If you know what you are doing you can disable this check using:

git config hooks.allownonascii true
EOF
exit 1
fi

# Fetch packages
echo "Running dart pub get..."
dart pub get >/dev/null
if [ $? -ne 0 ]; then
echo "dart pub get failed."
echo "Please run 'dart pub get' in the project root."
exit 1
fi

# Dart analyzer no errors should be found
echo "Running Dart analyzer..."
dart analyze
if [ $? -ne 0 ]; then
echo "Dart analyzer found issues."
echo "Please run 'dart analyze' in the project root."
exit 1
fi

# Dart tests should pass
echo "Running Dart tests..."
dart test . --fail-fast 1>/dev/null
# Print files that failed tests
if [ $? -ne 0 ]; then
echo "Dart tests failed."
echo "Please run 'dart test' in the project root."
exit 1
fi

# Dart fix --apply then any changed files should be added to the commit
echo "Running Dart fix..."
dart fix --apply .
git add .

# Dart format then any changed files should be added to the commit
echo "Running Dart format..."
dart format .
git add .

# return 0 to indicate that everything went well
echo "Pre-commit checks passed."
exit 0
3 changes: 3 additions & 0 deletions .idea/.gitignore

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

7 changes: 7 additions & 0 deletions .idea/codeStyles/Project.xml

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

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

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

6 changes: 6 additions & 0 deletions .idea/misc.xml

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

6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

5 changes: 5 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"default": true,
"MD013": false,
"MD033": false
}
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"dart-code.dart-code",
"streetsidesoftware.code-spell-checker",
"davidanson.vscode-markdownlint"
]
}
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"cSpell.words": [
"datetime",
"endtemplate",
"everies",
"overrider"
]
],
"dart.lineLength": 80
}
Loading
Loading