Skip to content

Commit 4e58f1c

Browse files
authored
Merge pull request #19 from comigor/fix-ci
Bump dependencies, fix CI
2 parents 5419ca0 + 2efbc07 commit 4e58f1c

14 files changed

+315
-103
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM makocchi/alpine-git-curl-jq
2+
3+
ENV OQ_VERSION 1.1.0
4+
RUN curl -L https://github.com/Blacksmoke16/oq/releases/download/v${OQ_VERSION}/oq-v${OQ_VERSION}-linux-x86_64 > /usr/local/bin/oq \
5+
&& chmod +x /usr/local/bin/oq
6+
7+
COPY entrypoint.sh /entrypoint.sh
8+
9+
ENTRYPOINT ["/entrypoint.sh"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: "Check version and changelog"
2+
description: "Make sure the version is bumped and it has a changelog entry"
3+
inputs:
4+
repo_token:
5+
description: "Access token for sending errors as a PR message"
6+
required: false
7+
default: ""
8+
base_ref:
9+
description: "GitHub base_ref"
10+
required: true
11+
default: ""
12+
outputs:
13+
package_version:
14+
description: "The package version"
15+
runs:
16+
using: "docker"
17+
image: "Dockerfile"
18+
args:
19+
- "${{ inputs.repo_token }}"
20+
- "${{ inputs.base_ref }}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/ash
2+
3+
cd "$GITHUB_WORKSPACE"
4+
5+
REPO_TOKEN="$1"
6+
github_ref="$2"
7+
8+
PR_HREF=$(cat "$GITHUB_EVENT_PATH" | jq -r '.pull_request._links.self.href')
9+
10+
function send_message_and_bail {
11+
ERROR="$1"
12+
13+
if [ ! -z "$REPO_TOKEN" ]; then
14+
jq -c -n --arg body "$ERROR" '{"event":"COMMENT", "body":$body}' > /tmp/payload.json
15+
curl -f -X POST \
16+
-H 'Content-Type: application/json' \
17+
-H "Authorization: Bearer $REPO_TOKEN" \
18+
--data "@/tmp/payload.json" \
19+
"$PR_HREF/reviews" -vv || true
20+
fi
21+
22+
echo "------------------------------------------------"
23+
echo "$ERROR"
24+
echo "------------------------------------------------"
25+
exit 1
26+
}
27+
28+
# echo "PARAM GITHUB REF: $github_ref"
29+
# echo "GITHUB EVENT NAME: $GITHUB_EVENT_NAME"
30+
# echo "GITHUB REF: $GITHUB_REF"
31+
# echo "GITHUB BASE REF: $GITHUB_BASE_REF"
32+
# echo "GITHUB HEAD REF: $GITHUB_HEAD_REF"
33+
34+
git fetch --prune --unshallow
35+
36+
if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
37+
where="origin/$github_ref"
38+
else
39+
where=HEAD~$(jq '.commits | length' "${GITHUB_EVENT_PATH}")
40+
fi
41+
42+
diff=$(git diff $where pubspec.yaml)
43+
44+
echo "$diff" | grep -E '\+.*version' || {
45+
send_message_and_bail "You must bump the version on pubspec!"
46+
}
47+
48+
package_version=$(cat pubspec.yaml | oq -i YAML -r '.version')
49+
50+
# If are on master or beta
51+
if [ "$github_ref" = "master" ] || [ "$github_ref" = "refs/heads/master" ]; then
52+
echo "$package_version" | grep "beta" && {
53+
send_message_and_bail "You can't merge a \"beta\" version on \`master\` branch!"
54+
}
55+
elif [ "$github_ref" = "beta" ] || [ "$github_ref" = "refs/heads/beta" ]; then
56+
echo "$package_version" | grep "beta" || {
57+
send_message_and_bail "You can only merge a \"beta\" version on \`beta\` branch!"
58+
}
59+
fi
60+
61+
cat CHANGELOG.md | grep -q "$package_version" || {
62+
send_message_and_bail "Version \`$package_version\` not found on CHANGELOG!"
63+
}
64+
65+
echo "::set-output name=package_version::$package_version"

.github/actions/dart-test/Dockerfile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM cirrusci/flutter
2+
3+
USER root
4+
5+
RUN apt update && apt install -y jq
6+
7+
ADD entrypoint.sh /entrypoint.sh
8+
ENTRYPOINT ["/entrypoint.sh"]

.github/actions/dart-test/action.yaml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: "Run linter and tests on a Dart package"
2+
description: "Run linter and tests on a Dart package"
3+
inputs:
4+
repo_token:
5+
description: "Access token for sending errors as a PR message"
6+
required: false
7+
is_flutter:
8+
description: "Run everything on Flutter context instead of Dart's"
9+
required: false
10+
default: "false"
11+
disable_linter:
12+
description: "Disable dry-run dartfmt linter check"
13+
required: false
14+
default: "false"
15+
disable_analyzer:
16+
description: "Disable dartanalyzer"
17+
required: false
18+
default: "false"
19+
disable_tests:
20+
description: "Disable pub run test"
21+
required: false
22+
default: "false"
23+
exclude_regex:
24+
description: "Regex to be used to exclude folders when looking for pubspec.yaml files"
25+
required: false
26+
default: "__________________"
27+
runs:
28+
using: "docker"
29+
image: "Dockerfile"
30+
args:
31+
- "${{ inputs.repo_token }}"
32+
- "${{ inputs.is_flutter }}"
33+
- "${{ inputs.disable_linter }}"
34+
- "${{ inputs.disable_analyzer }}"
35+
- "${{ inputs.disable_tests }}"
36+
- "${{ inputs.exclude_regex }}"
+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
REPO_TOKEN="$1"
6+
DTA_IS_FLUTTER="$2"
7+
DTA_DISABLE_LINTER="$3"
8+
DTA_DISABLE_ANALYZER="$4"
9+
DTA_DISABLE_TESTS="$5"
10+
DTA_EXCLUDE_REGEX="$6"
11+
12+
echo "DTA_IS_FLUTTER=$DTA_IS_FLUTTER"
13+
echo "DTA_DISABLE_LINTER=$DTA_DISABLE_LINTER"
14+
echo "DTA_DISABLE_ANALYZER=$DTA_DISABLE_ANALYZER"
15+
echo "DTA_DISABLE_TESTS=$DTA_DISABLE_TESTS"
16+
echo "DTA_EXCLUDE_REGEX=$DTA_EXCLUDE_REGEX"
17+
18+
cd "$GITHUB_WORKSPACE"
19+
20+
PR_HREF=$(cat "$GITHUB_EVENT_PATH" | jq -r '.pull_request._links.self.href')
21+
22+
function send_message_and_bail {
23+
ERROR="$1"
24+
DETAIL="$2"
25+
26+
if [ ! -z "$REPO_TOKEN" ]; then
27+
BODY=$(cat <<EOF
28+
$ERROR
29+
30+
<details>
31+
<pre>
32+
$DETAIL
33+
</pre>
34+
</details>
35+
EOF
36+
)
37+
38+
jq -c -n --arg body "$BODY" '{"event":"COMMENT", "body":$body}' > /tmp/payload.json
39+
curl -f -X POST \
40+
-H 'Content-Type: application/json' \
41+
-H "Authorization: Bearer $REPO_TOKEN" \
42+
--data "@/tmp/payload.json" \
43+
"$PR_HREF/reviews" -vv || true
44+
fi
45+
46+
echo "------------------------------------------------"
47+
echo "$ERROR"
48+
echo "$DETAIL"
49+
echo "------------------------------------------------"
50+
exit 1
51+
}
52+
53+
for ppath in $(find . -name pubspec.yaml | grep -ve "$DTA_EXCLUDE_REGEX"); do
54+
echo "=== On $ppath ==="
55+
cd $(dirname "$ppath");
56+
57+
echo "=== Downloading dependencies ==="
58+
if [ "$DTA_IS_FLUTTER" = "false" ]; then
59+
pub get
60+
else
61+
flutter pub get
62+
fi
63+
64+
if [ "$DTA_DISABLE_LINTER" = "false" ]; then
65+
echo "=== Running linter ==="
66+
OUTPUT=$(dartfmt -n . --set-exit-if-changed 2>&1)
67+
68+
if [ $? -ne 0 ]; then
69+
send_message_and_bail "Linter has failed! \`dartfmt -n . --set-exit-if-changed\`:" "$OUTPUT"
70+
fi
71+
fi
72+
73+
if [ "$DTA_DISABLE_ANALYZER" = "false" ]; then
74+
echo "=== Running analyzer ==="
75+
OUTPUT=$(dartanalyzer --fatal-infos --fatal-warnings . 2>&1) || send_message_and_bail "Analyzer has failed! \`dartanalyzer --fatal-infos --fatal-warnings .\`:" "$OUTPUT"
76+
fi
77+
78+
[ -d "test" ] && {
79+
if [ "$DTA_DISABLE_TESTS" = "false" ]; then
80+
echo "=== Running tests ==="
81+
if [ "$DTA_IS_FLUTTER" = "false" ]; then
82+
OUTPUT=$(pub run test --no-color -r expanded 2>&1) || send_message_and_bail "Tests failed!" "$OUTPUT"
83+
else
84+
OUTPUT=$(flutter test 2>&1) || send_message_and_bail "Tests have failed! \`pub run test\`:" "$OUTPUT"
85+
fi
86+
fi
87+
}
88+
89+
# Go back
90+
cd -
91+
done

.github/workflows/actions.yml

-78
This file was deleted.

.github/workflows/pull_request.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
on: pull_request
2+
3+
name: CI
4+
5+
jobs:
6+
check-version-and-changelog:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@master
10+
- uses: ./.github/actions/check-version-and-changelog
11+
with:
12+
repo_token: "${{ secrets.GITHUB_TOKEN }}"
13+
base_ref: "${{ github.base_ref }}"
14+
test:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@master
18+
- uses: ./.github/actions/dart-test
19+
with:
20+
repo_token: "${{ secrets.GITHUB_TOKEN }}"
21+
exclude_regex: "example"

.github/workflows/push.yaml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
on:
2+
push:
3+
branches:
4+
- master
5+
- beta
6+
7+
name: CI
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/beta'
13+
steps:
14+
- name: Clone repository
15+
uses: actions/checkout@master
16+
- name: Run tests
17+
uses: comigor/actions/dart-test@master
18+
env:
19+
DTA_EXCLUDE_REGEX: example
20+
create-tag-and-release:
21+
needs: test
22+
runs-on: ubuntu-latest
23+
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/beta'
24+
steps:
25+
- uses: actions/checkout@master
26+
- id: check_version_and_changelog
27+
name: Check if version on pubspec.yaml was changed and if there's an entry for this new version on CHANGELOG
28+
uses: ./.github/actions/check-version-and-changelog
29+
with:
30+
base_ref: "${{ github.ref }}"
31+
- name: Push tag
32+
uses: anothrNick/github-tag-action@master
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
CUSTOM_TAG: "v${{ steps.check_version_and_changelog.outputs.package_version }}"
36+
- name: Create release
37+
uses: actions/create-release@v1
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
with:
41+
tag_name: "v${{ steps.check_version_and_changelog.outputs.package_version }}"
42+
release_name: "Release v${{ steps.check_version_and_changelog.outputs.package_version }}"
43+
deploy:
44+
needs: create-tag-and-release
45+
runs-on: ubuntu-latest
46+
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/beta'
47+
steps:
48+
- uses: actions/checkout@master
49+
- name: Publish to pub.dev
50+
uses: comigor/actions/pub-publish@master
51+
env:
52+
PUB_CREDENTIALS: ${{ secrets.PUB_CREDENTIALS }}

0 commit comments

Comments
 (0)