Fix yaml syntax error #71
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build app | |
on: | |
push: | |
paths: | |
- ".github/workflows/build.yaml" | |
- "android/**" | |
- "lib/**" | |
- "web/**" | |
- "analysis_options.yaml" | |
- "CHANGELOG.md" | |
- "pubspec.yaml" | |
- "pubspec.lock" | |
pull_request: | |
paths: | |
- ".github/workflows/build.yaml" | |
- "android/**" | |
- "lib/**" | |
- "web/**" | |
- "analysis_options.yaml" | |
- "pubspec.yaml" | |
- "pubspec.lock" | |
env: | |
JAVA_VERSION: "17" | |
JAVA_DISTRIBUTION: temurin | |
FLUTTER_CHANNEL: beta | |
permissions: | |
contents: read | |
jobs: | |
lint: | |
name: Lint code | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Install Java | |
uses: actions/setup-java@v4 | |
with: | |
distribution: ${{ env.JAVA_DISTRIBUTION }} | |
java-version: ${{ env.JAVA_VERSION }} | |
- name: Install Flutter | |
uses: subosito/flutter-action@v2 | |
with: | |
channel: ${{ env.FLUTTER_CHANNEL }} | |
cache: "true" | |
- name: Get Flutter dependencies | |
run: flutter pub get | |
- name: Generate missing files | |
run: dart run build_runner build | |
- name: Analyze code | |
run: flutter analyze | |
- name: Check formatting | |
run: > | |
find lib/ -name '*.dart' -not -name '*.g.dart' | |
| xargs dart format --set-exit-if-changed --output none --line-length=100 | |
build-apk: | |
name: Build app for Android | |
runs-on: ubuntu-latest | |
needs: | |
- lint | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Install Java | |
uses: actions/setup-java@v4 | |
with: | |
distribution: ${{ env.JAVA_DISTRIBUTION }} | |
java-version: ${{ env.JAVA_VERSION }} | |
cache: gradle | |
- name: Install Flutter | |
uses: subosito/flutter-action@v2 | |
with: | |
channel: ${{ env.FLUTTER_CHANNEL }} | |
cache: "true" | |
- name: Get Flutter dependencies | |
run: flutter pub get | |
- name: Generate missing files | |
run: dart run build_runner build | |
- name: Decode keystore file | |
env: | |
KEYSTORE_CONTENTS: ${{ secrets.KEYSTORE_CONTENTS }} | |
run: | | |
echo "$KEYSTORE_CONTENTS" | base64 -d >android/keystore.jks | |
- name: Build app for Android | |
env: | |
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }} | |
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} | |
run: | | |
BUILD_FLAVOR="dev" | |
if [[ "${GITHUB_REF}" == "refs/tags/v"* ]]; then | |
BUILD_FLAVOR="prod" | |
fi | |
flutter build apk --release --split-per-abi --flavor "${BUILD_FLAVOR?}" | |
- name: Upload APK artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: android-apks | |
if-no-files-found: error | |
path: | | |
build/app/outputs/flutter-apk/app-*.apk | |
build/app/outputs/flutter-apk/app-*.apk.sha1 | |
- name: Send dev APK to testers Telegram group | |
if: "!startsWith(github.ref, 'refs/tags/v')" | |
env: | |
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} | |
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} | |
run: | | |
actual_version="$(git describe --tags --always | sed -E 's/(-([0-9]+)-g([0-9a-f]+))?$/.r\2-\3/g')" | |
curl --silent --show-error --fail-with-body \ | |
-F "chat_id=${TELEGRAM_CHAT_ID}" \ | |
-F "document=@build/app/outputs/flutter-apk/app-arm64-v8a-dev-release.apk" \ | |
-F "caption=New version: ${actual_version}" \ | |
"https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendDocument" \ | |
>/dev/null | |
continue-on-error: true | |
build-web: | |
name: Build app for web | |
runs-on: ubuntu-latest | |
needs: | |
- lint | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Install Java | |
uses: actions/setup-java@v4 | |
with: | |
distribution: ${{ env.JAVA_DISTRIBUTION }} | |
java-version: ${{ env.JAVA_VERSION }} | |
- name: Install Flutter | |
uses: subosito/flutter-action@v2 | |
with: | |
channel: ${{ env.FLUTTER_CHANNEL }} | |
cache: true | |
- name: Get Flutter dependencies | |
run: flutter pub get | |
- name: Generate missing files | |
run: dart run build_runner build | |
- name: Build app for web | |
run: flutter build web | |
- name: Patch app name for web | |
run: | | |
jq -c '.app_name = "Mafia companion"' build/web/version.json >build/web/version.new.json | |
mv build/web/version{.new,}.json | |
- name: Upload web artifact | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: build/web/ | |
publish-web: | |
name: Publish web build on GitHub Pages | |
runs-on: ubuntu-latest | |
needs: | |
- build-web | |
permissions: | |
pages: write | |
id-token: write | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
if: startsWith(github.ref, 'refs/tags/v') | |
steps: | |
- name: Publish web on GitHub pages | |
id: deployment | |
uses: actions/deploy-pages@v4 | |
create-release: | |
name: Create release | |
runs-on: ubuntu-latest | |
needs: | |
- build-apk | |
permissions: | |
contents: write | |
if: startsWith(github.ref, 'refs/tags/v') | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Download APK artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: android-apks | |
path: build | |
- name: Generate release notes | |
id: release_notes | |
run: | | |
file="$(mktemp --suffix=.md)" | |
previous_tag="$(git describe --tags --abbrev=0 "${GITHUB_REF_NAME}^")" | |
start_line="$(grep -En "## \[v?$GITHUB_REF_NAME\]" CHANGELOG.md | cut -d ':' -f 1)" | |
end_line="$(grep -En "## \[v?$previous_tag\]" CHANGELOG.md | cut -d ':' -f 1)" | |
sed -n "$((${start_line} + 1)),$((${end_line} - 1))p" CHANGELOG.md >$file | |
sed -Ei 's/###/##/;1{/^\s*$/d}' $file | |
# ChatGPT-powered magic to remove trailing empty lines | |
sed -i ':l;/^\n*$/{$d;N;bl;}' $file | |
echo -ne '\n## Commits\n\n' >>$file | |
git log --format="- %h: %s (%aN)" "${previous_tag}..${GITHUB_REF_NAME}" >>$file | |
echo "$GITHUB_REF_NAME" | awk '{ print "prerelease=" (($1 ~ /v[0-9]+\.[0-9]+\.[0-9]+-.+/) ? "true" : "false"); }' >>$GITHUB_OUTPUT | |
echo "release_notes=$file" >>$GITHUB_OUTPUT | |
- name: Create a release | |
uses: softprops/action-gh-release@v2 | |
with: | |
body_path: ${{ steps.release_notes.outputs.release_notes }} | |
prerelease: ${{ steps.release_notes.outputs.prerelease }} | |
files: | | |
build/app-*.apk | |
fail_on_unmatched_files: true | |
- name: Send release info to testers Telegram group | |
env: | |
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} | |
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} | |
run: | | |
release_url="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/releases/tag/${GITHUB_REF_NAME}" | |
curl --silent --show-error --fail-with-body \ | |
-F "chat_id=${TELEGRAM_CHAT_ID}" \ | |
-F "parse_mode=MarkdownV2" \ | |
-F "text=New release: [${GITHUB_REF_NAME}](${release_url})" \ | |
"https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \ | |
>/dev/null | |
continue-on-error: true |