Update main.yml #12
This file contains hidden or 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 & Release" | |
on: | |
pull_request: | |
branches: | |
- main | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
name: Build & Release | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
with: | |
repository: fskhri/jeketi-v2 | |
token: ${{ secrets.TOKEN }} | |
# Cache Flutter SDK | |
- name: Cache Flutter SDK | |
uses: actions/cache@v3 | |
with: | |
path: ~/.flutter-sdk | |
key: ${{ runner.os }}-flutter-sdk-${{ hashFiles('pubspec.yaml') }} | |
restore-keys: | | |
${{ runner.os }}-flutter-sdk- | |
- name: Set Up Flutter | |
if: steps.cache-flutter-sdk.outputs.cache-hit != 'true' | |
run: | | |
git clone https://github.com/flutter/flutter.git -b stable ~/.flutter-sdk | |
echo "$HOME/.flutter-sdk/bin" >> $GITHUB_PATH | |
# Cache Pub Dependencies | |
- name: Cache Flutter Packages | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.pub-cache | |
.packages | |
.flutter-plugins | |
.flutter-plugins-dependencies | |
key: ${{ runner.os }}-pub-cache-${{ hashFiles('pubspec.yaml') }} | |
restore-keys: | | |
${{ runner.os }}-pub-cache- | |
- name: Set Up Java | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'adopt' | |
java-version: '17' | |
- name: Install Dependencies | |
run: flutter pub get | |
- name: Build APK | |
run: flutter build apk --release | |
- name: Extract version from pubspec.yaml | |
id: extract_version | |
run: | | |
version=$(grep '^version: ' pubspec.yaml | cut -d ' ' -f 2 | tr -d '\r') | |
echo "VERSION=$version" >> $GITHUB_ENV | |
- name: Generate Unique Tag | |
id: generate_tag | |
run: | | |
base_version="${{ env.VERSION }}" | |
unique_tag="${base_version}-build-${{ github.run_number }}" | |
echo "UNIQUE_TAG=$unique_tag" >> $GITHUB_ENV | |
- name: Get Previous Tag | |
id: get_prev_tag | |
run: | | |
prev_tag=$(git describe --tags --abbrev=0) | |
echo "PREV_TAG=$prev_tag" >> $GITHUB_ENV | |
- name: Generate Changelog from Commits | |
id: generate_changelog | |
run: | | |
changelog=$(git log ${{ env.PREV_TAG }}..HEAD --pretty=format:"%h - %s (%an)") | |
echo "CHANGELOG=$changelog" >> $GITHUB_ENV | |
- name: Create Release | |
uses: ncipollo/release-action@v1 | |
with: | |
artifacts: "build/app/outputs/flutter-apk/app-release.apk" | |
tag: v${{ env.UNIQUE_TAG }} | |
token: ${{ secrets.KOCAK }} | |
name: "Release v${{ env.UNIQUE_TAG }}" | |
body: | | |
## Changelog | |
${{ env.CHANGELOG }} | |
- name: Checkout jeketi-app Repository | |
uses: actions/checkout@v3 | |
with: | |
repository: fskhri/jeketi-app | |
token: ${{ secrets.TOKEN }} |