v1.0.0 - Initial release (#1)
CI and Release / format (push) Successful in 34s
CI and Release / analyze (push) Successful in 26s
CI and Release / test (push) Successful in 48s
CI and Release / pana (push) Successful in 2m9s
CI and Release / version-and-changelog (push) Successful in 20s
CI and Release / publish (push) Failing after 13s
CI and Release / format (push) Successful in 34s
CI and Release / analyze (push) Successful in 26s
CI and Release / test (push) Successful in 48s
CI and Release / pana (push) Successful in 2m9s
CI and Release / version-and-changelog (push) Successful in 20s
CI and Release / publish (push) Failing after 13s
Initial release 🥳 Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
@@ -0,0 +1,287 @@
|
||||
name: CI and Release
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
format:
|
||||
name: format
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Dart
|
||||
uses: dart-lang/setup-dart@v1
|
||||
- name: Install dependencies
|
||||
run: dart pub get
|
||||
- name: Check formatting
|
||||
run: dart format --output=none --set-exit-if-changed .
|
||||
|
||||
analyze:
|
||||
name: analyze
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Dart
|
||||
uses: dart-lang/setup-dart@v1
|
||||
- name: Install dependencies
|
||||
run: dart pub get
|
||||
- name: Run analyzer
|
||||
run: dart analyze --fatal-infos
|
||||
|
||||
test:
|
||||
name: test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Dart
|
||||
uses: dart-lang/setup-dart@v1
|
||||
- name: Install dependencies
|
||||
run: dart pub get
|
||||
- name: Run tests
|
||||
run: dart test
|
||||
|
||||
pana:
|
||||
name: pana
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Dart
|
||||
uses: dart-lang/setup-dart@v1
|
||||
- name: Install dependencies
|
||||
run: dart pub get
|
||||
- name: Run pana and enforce full score
|
||||
run: |
|
||||
set -euo pipefail
|
||||
dart pub global activate pana
|
||||
export PATH="$PATH:$HOME/.pub-cache/bin"
|
||||
|
||||
pana . | tee /tmp/pana.log
|
||||
|
||||
SCORE_LINE="$(grep -Eo 'Points: [0-9]+/[0-9]+' /tmp/pana.log | tail -n1 || true)"
|
||||
if [ -z "$SCORE_LINE" ]; then
|
||||
echo "Could not parse pana score output."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SCORE="${SCORE_LINE#Points: }"
|
||||
GOT="${SCORE%/*}"
|
||||
MAX="${SCORE#*/}"
|
||||
|
||||
if [ "$GOT" -ne "$MAX" ]; then
|
||||
echo "Pana score must be full. Got $SCORE."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Pana full score confirmed: $SCORE"
|
||||
|
||||
version_and_changelog:
|
||||
name: version-and-changelog
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Validate release metadata for PRs into main
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
if [ "${GITHUB_EVENT_NAME}" != "pull_request" ]; then
|
||||
echo "Not a pull_request event; skipping version/changelog gate."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ -z "${GITHUB_BASE_REF:-}" ]; then
|
||||
echo "GITHUB_BASE_REF is not set for pull_request event."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
git fetch origin "${GITHUB_BASE_REF}" --depth=1
|
||||
|
||||
PR_VERSION="$(sed -nE 's/^version:\s*([^[:space:]]+)\s*$/\1/p' pubspec.yaml | head -n1)"
|
||||
BASE_HAS_PUBSPEC="false"
|
||||
BASE_VERSION=""
|
||||
|
||||
if git cat-file -e "origin/${GITHUB_BASE_REF}:pubspec.yaml" 2>/dev/null; then
|
||||
BASE_HAS_PUBSPEC="true"
|
||||
BASE_VERSION="$(git show "origin/${GITHUB_BASE_REF}:pubspec.yaml" | sed -nE 's/^version:\s*([^[:space:]]+)\s*$/\1/p' | head -n1)"
|
||||
fi
|
||||
|
||||
if [ -z "$PR_VERSION" ]; then
|
||||
echo "Unable to read version from PR pubspec.yaml."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$BASE_HAS_PUBSPEC" = "true" ]; then
|
||||
if [ -z "$BASE_VERSION" ]; then
|
||||
echo "Unable to read version from base branch pubspec.yaml."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
parse_semver_core() {
|
||||
printf '%s' "$1" | sed -E 's/^([0-9]+\.[0-9]+\.[0-9]+).*/\1/'
|
||||
}
|
||||
|
||||
BASE_CORE="$(parse_semver_core "$BASE_VERSION")"
|
||||
PR_CORE="$(parse_semver_core "$PR_VERSION")"
|
||||
|
||||
if ! printf '%s' "$BASE_CORE" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
|
||||
echo "Base version is not valid semver: $BASE_VERSION"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! printf '%s' "$PR_CORE" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
|
||||
echo "PR version is not valid semver: $PR_VERSION"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BASE_MAJOR="${BASE_CORE%%.*}"
|
||||
BASE_REST="${BASE_CORE#*.}"
|
||||
BASE_MINOR="${BASE_REST%%.*}"
|
||||
BASE_PATCH="${BASE_REST#*.}"
|
||||
|
||||
PR_MAJOR="${PR_CORE%%.*}"
|
||||
PR_REST="${PR_CORE#*.}"
|
||||
PR_MINOR="${PR_REST%%.*}"
|
||||
PR_PATCH="${PR_REST#*.}"
|
||||
|
||||
if [ "$PR_MAJOR" -lt "$BASE_MAJOR" ]; then
|
||||
echo "pubspec.yaml version must be greater than base version ($BASE_VERSION -> $PR_VERSION)."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$PR_MAJOR" -eq "$BASE_MAJOR" ] && [ "$PR_MINOR" -lt "$BASE_MINOR" ]; then
|
||||
echo "pubspec.yaml version must be greater than base version ($BASE_VERSION -> $PR_VERSION)."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$PR_MAJOR" -eq "$BASE_MAJOR" ] && [ "$PR_MINOR" -eq "$BASE_MINOR" ] && [ "$PR_PATCH" -le "$BASE_PATCH" ]; then
|
||||
echo "pubspec.yaml version must be at least 0.0.1 greater than base version ($BASE_VERSION -> $PR_VERSION)."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "Base branch has no pubspec.yaml; treating this as first release."
|
||||
fi
|
||||
|
||||
if git diff --quiet "origin/${GITHUB_BASE_REF}...HEAD" -- CHANGELOG.md; then
|
||||
echo "CHANGELOG.md must be updated in the PR."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! grep -Fq "## $PR_VERSION" CHANGELOG.md && ! grep -Fq "## [$PR_VERSION]" CHANGELOG.md; then
|
||||
echo "CHANGELOG.md must include a heading for version $PR_VERSION."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$BASE_HAS_PUBSPEC" = "true" ]; then
|
||||
echo "Version/changelog gate passed: $BASE_VERSION -> $PR_VERSION"
|
||||
else
|
||||
echo "Version/changelog gate passed for first release: $PR_VERSION"
|
||||
fi
|
||||
|
||||
publish:
|
||||
name: publish
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- format
|
||||
- analyze
|
||||
- test
|
||||
- pana
|
||||
- version_and_changelog
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Dart
|
||||
uses: dart-lang/setup-dart@v1
|
||||
- name: Publish package and create Gitea release on push to main
|
||||
env:
|
||||
PUB_CREDENTIALS_JSON: ${{ secrets.PUB_CREDENTIALS_JSON }}
|
||||
RELEASE_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
FALLBACK_RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
if [ "${GITHUB_EVENT_NAME}" != "push" ] || [ "${GITHUB_REF}" != "refs/heads/main" ]; then
|
||||
echo "Not a push to main; skipping publish."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
PACKAGE_NAME="$(sed -nE 's/^name:\s*([^[:space:]]+)\s*$/\1/p' pubspec.yaml | head -n1)"
|
||||
PACKAGE_VERSION="$(sed -nE 's/^version:\s*([^[:space:]]+)\s*$/\1/p' pubspec.yaml | head -n1)"
|
||||
|
||||
if [ -z "$PACKAGE_NAME" ] || [ -z "$PACKAGE_VERSION" ]; then
|
||||
echo "Failed to parse package name/version from pubspec.yaml."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if curl -fsSL "https://pub.dev/api/packages/${PACKAGE_NAME}" | grep -q "\"version\":\"${PACKAGE_VERSION}\""; then
|
||||
echo "${PACKAGE_NAME} ${PACKAGE_VERSION} is already published; skipping."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ -z "${PUB_CREDENTIALS_JSON:-}" ]; then
|
||||
echo "Missing required secret PUB_CREDENTIALS_JSON."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$HOME/.pub-cache"
|
||||
printf '%s' "$PUB_CREDENTIALS_JSON" > "$HOME/.pub-cache/credentials.json"
|
||||
chmod 600 "$HOME/.pub-cache/credentials.json"
|
||||
|
||||
dart pub get
|
||||
dart pub publish --dry-run
|
||||
dart pub publish --force
|
||||
|
||||
TOKEN="${RELEASE_TOKEN:-}"
|
||||
if [ -z "$TOKEN" ]; then
|
||||
TOKEN="${FALLBACK_RELEASE_TOKEN:-}"
|
||||
fi
|
||||
|
||||
if [ -z "$TOKEN" ]; then
|
||||
echo "Missing release token. Provide default workflow token or RELEASE_TOKEN."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SERVER_URL="${GITHUB_SERVER_URL:-${GITEA_SERVER_URL:-}}"
|
||||
REPO_PATH="${GITHUB_REPOSITORY:-${GITEA_REPOSITORY:-}}"
|
||||
|
||||
if [ -z "$SERVER_URL" ] || [ -z "$REPO_PATH" ]; then
|
||||
echo "Missing repository context required for Gitea API release creation."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TAG="v${PACKAGE_VERSION}"
|
||||
RELEASE_BY_TAG_URL="${SERVER_URL}/api/v1/repos/${REPO_PATH}/releases/tags/${TAG}"
|
||||
|
||||
if curl -fsS -H "Authorization: token ${TOKEN}" "$RELEASE_BY_TAG_URL" >/dev/null; then
|
||||
echo "Release ${TAG} already exists; skipping release creation."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
CREATE_RELEASE_URL="${SERVER_URL}/api/v1/repos/${REPO_PATH}/releases"
|
||||
RELEASE_PAYLOAD="{\"tag_name\":\"${TAG}\",\"target\":\"${GITHUB_SHA}\",\"target_commitish\":\"${GITHUB_SHA}\",\"title\":\"${TAG}\",\"name\":\"${TAG}\",\"note\":\"Release ${TAG}\",\"body\":\"Release ${TAG}\",\"draft\":false,\"prerelease\":false}"
|
||||
|
||||
HTTP_CODE="$(curl -sS -o /tmp/gitea-release-response.json -w '%{http_code}' \
|
||||
-X POST "$CREATE_RELEASE_URL" \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d "$RELEASE_PAYLOAD")"
|
||||
|
||||
if [ "$HTTP_CODE" = "201" ]; then
|
||||
echo "Created Gitea release for ${TAG}."
|
||||
elif [ "$HTTP_CODE" = "409" ]; then
|
||||
echo "Release or tag ${TAG} already exists; treating as success."
|
||||
else
|
||||
echo "Failed to create Gitea release. HTTP ${HTTP_CODE}."
|
||||
cat /tmp/gitea-release-response.json
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user