Skip to content

Commit

Permalink
build: Added GitHub Actions pipeline to release app to GitHub releases
Browse files Browse the repository at this point in the history
  • Loading branch information
uSlashVlad committed Sep 15, 2024
1 parent aecdd1e commit cc614b5
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 3 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ on:
jobs:
check:
name: Check application

runs-on: ubuntu-latest

steps:
### INITIAL ###
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.24.1'
flutter-version: '3.24.2'
channel: stable
cache: true
- uses: actions/cache@v3
Expand Down
146 changes: 146 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
name: App release

on:
push:
tags:
- 'release/*'

jobs:
check:
name: Check application
runs-on: ubuntu-latest
steps:
# Init
- name: Checkout repository
uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.24.2'
channel: stable
cache: true
- uses: actions/cache@v3
with:
path: |
~/.pub-cache/git
~/.pub-cache/hosted
- name: Check flutter installation
run: flutter --version
# Preparation
- name: Get dependencies
run: dart run melos bootstrap
# Checks
- name: Ensure that code is formatted correctly
run: dart run melos format --set-exit-if-changed --output none $(git ls-files | grep --colour=never -e ".*\.dart")
- name: Analyze code to find critical problems
run: dart run melos exec flutter analyze --no-fatal-infos
# Update generation and locale if needed
- name: Generate with build_runner
run: dart run melos run generate
- name: Update locale
run: dart run melos run l10n

version_update:
name: Update pubspec version
needs: check
runs-on: ubuntu-latest
outputs:
app_version: ${{ steps.update_version.outputs.app_version }}
app_build_number: ${{ steps.update_version.outputs.app_build_number }}
tag_name: ${{ steps.get_tag.outputs.tag_name }}
branch: ${{ steps.find_branch.outputs.branch }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get Tag Name
id: get_tag
run: echo "tag_name=${GITHUB_REF##*/}" >> $GITHUB_OUTPUT
- name: Find Branch Containing the Tag Commit
id: find_branch
run: |
BRANCH=$(git branch -r --contains $GITHUB_SHA | grep -v HEAD | head -n 1 | sed 's|origin/||')
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
- name: Checkout Branch
run: git checkout ${{ steps.find_branch.outputs.branch }}
- name: Update Version
run: tools/update_version.sh ${{ steps.get_tag.outputs.tag_name }} >> $GITHUB_OUTPUT
- name: Validate release notes
run: tools/validate_release_notes.sh ${{ steps.update_version.outputs.app_version }}
- name: Commit and Push Changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add pubspec.yaml
git commit -m "Bump version to ${{ steps.update_version.outputs.new_version }} [skip ci]"
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}
git push origin HEAD:${{ steps.find_branch.outputs.branch }}
build:
name: Build android
needs: version_update
runs-on: ubuntu-latest
steps:
# Init
- name: Checkout Repository
uses: actions/checkout@v3
with:
ref: ${{ needs.version_update.outputs.branch }}
fetch-depth: 0
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.24.2'
channel: stable
cache: true
- uses: actions/cache@v3
with:
path: |
~/.pub-cache/git
~/.pub-cache/hosted
- name: Check flutter installation
run: flutter --version
# Preparation
- name: Get dependencies
run: dart run melos bootstrap
- name: Decode and save android keystore
run: |
echo "${{ secrets.ANDROID_KEYSTORE_BASE64 }}" | base64 --decode > $HOME/keystore.jks
- name: Save key.properties
run: |
touch android/key.properties
echo "storePassword=${{ secrets.ANDROID_KEYSTORE_PASSWORD }}" >> android/key.properties
echo "keyPassword=${{ secrets.ANDROID_KEY_PASSWORD }}" >> android/key.properties
echo "keyAlias=${{ secrets.ANDROID_KEY_ALIAS }}" >> android/key.properties
echo "storeFile=$HOME/keystore.jks" >> android/key.properties
# Build and upload
- name: Build APK
run: |
flutter build apk --flavor prod --split-per-abi
flutter build apk --flavor prod
TAG=foss tools/android/move-builds.sh
tools/android/check-cert.sh
- name: Upload FOSS APK Artifact
uses: actions/upload-artifact@v3
with:
name: artifacts-apk-foss
path: build/releases/android

release:
name: Release to GitHub actions
needs: build
runs-on: ubuntu-latest
steps:
- name: Download APKs Directory
uses: actions/download-artifact@v3
with:
name: artifacts-apk-foss
- name: Create GitHub Release
uses: ncipollo/release-action@v1
with:
tag: ${{ needs.version_update.outputs.tag_name }}
name: v${{ needs.version_update.outputs.app_version }}
bodyFile: release_notes/${{ needs.version_update.outputs.app_version }}/github/RELEASE_NOTES.md
files: 'artifacts-apk-foss/*.apk'
token: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions release_notes/0.11.3/github/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.11.2

Test release using GitHub Actions
3 changes: 3 additions & 0 deletions tools/android/check-cert.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

# Run this file like this:
# sh android/tools/check-cert.sh app-arm64-v8a-release.apk

Expand All @@ -11,6 +13,7 @@ check_cert () {
echo -e "\033[92m ✔️ \"$1\" certificate fingerprint valid\033[0m"
else
echo -e "\033[93m ⚠️ \"$1\" hasn't got trusted certificate fingerprint\033[0m"
exit 1
fi
}

Expand Down
2 changes: 2 additions & 0 deletions tools/android/move-builds.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

APK_DIR="build/app/outputs/flutter-apk"
AAB_DIR="build/app/outputs/bundle/release"
RELEASE_DIR="build/releases/android"
Expand Down
2 changes: 2 additions & 0 deletions tools/copy_artifact.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

if [ -f $1 ]; then
cp $1 $2
else
Expand Down
2 changes: 2 additions & 0 deletions tools/get-version.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#!/bin/bash

cat pubspec.yaml | grep "version: " | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+"
2 changes: 2 additions & 0 deletions tools/linux/move-builds.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

LINUX_DIR="build/linux/x64/release"
RELEASE_DIR="build/releases/linux"
APP_NAME="not_zero-linux"
Expand Down
15 changes: 15 additions & 0 deletions tools/update-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

TAG_VERSION="$(echo "$1" | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+")"

CURRENT_VERSION=$(grep '^version: ' pubspec.yaml | sed 's/version: //')
CURRENT_BUILD_NUMBER=$(echo "$CURRENT_VERSION" | cut -d'+' -f2)

if [ -z "$CURRENT_BUILD_NUMBER" ]; then
CURRENT_BUILD_NUMBER=0
fi
NEW_BUILD_NUMBER=$((CURRENT_BUILD_NUMBER + 1))

sed -i "s/version: $CURRENT_VERSION/version: $TAG_VERSION+$NEW_BUILD_NUMBER/" pubspec.yaml

echo -e "app_version=$TAG_VERSION\n""app_build_number=$NEW_BUILD_NUMBER"
9 changes: 9 additions & 0 deletions tools/validate_release_notes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

RELEASE_DIR="release_notes/$1"
RELEASE_FILENAME="RELEASE_NOTES.md"

if [ ! -f "$RELEASE_DIR/github/$RELEASE_FILENAME" ]; then
echo "Release notes file for GitHub not found"
exit 1
fi

0 comments on commit cc614b5

Please sign in to comment.