Skip to content

Commit

Permalink
git action created to release to GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Harshana-Rathnayaka committed May 23, 2022
1 parent a619368 commit 5c4e6ff
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 1 deletion.
110 changes: 110 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Analyze, Build and Release to GitHub
on:
push:
tags:
- "v*"

jobs:
# creating the version number for both GitHub and Pubspec file
version:
name: Create version number
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Fetch all history for all tags and branches
run: |
git config remote.origin.url https://x-access-token:${{ secrets.TOKEN }}@github.com/${{ github.repository }}
git fetch --prune --depth=10000
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0.9.7
with:
versionSpec: "5.x"

- name: Use GitVersion
id: gitversion
uses: gittools/actions/gitversion/execute@v0.9.7

- name: Create version.txt with nuGetVersion
run: echo ${{ steps.gitversion.outputs.nuGetVersion }} > version.txt

- name: Upload version.txt
uses: actions/upload-artifact@v2
with:
name: gitversion
path: version.txt

# building the appbundle after updating the version in Pubspec file from the version number created before
build:
name: Analyze and build APKs and Appbundle (Android)
needs: [version]
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

# version text created earlier
- name: Get version.txt
uses: actions/download-artifact@v2
with:
name: gitversion

- name: Create new file without newline char from version.txt
run: tr -d '\n' < version.txt > version1.txt

- name: Read version
id: version
uses: juliangruber/read-file-action@v1
with:
path: version1.txt

# updating that version in pubspec
- name: Update version in YAML
run: sed -i 's/99.99.99+99/${{ steps.version.outputs.content }}+${{ github.run_number }}/g' pubspec.yaml

# setting up environment for build
- name: Setup Java
uses: actions/setup-java@v1
with:
java-version: "12.x"

- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: "2.10.x"
channel: "stable"

- name: Cache pub dependencies
uses: actions/cache@v2
with:
path: ${{ env.FLUTTER_HOME }}/.pub-cache
key: ${{ runner.os }}-pub-${{ hashFiles('**/pubspec.lock') }}
restore-keys: ${{ runner.os }}-pub-

- name: Download pub dependencies
run: flutter pub get

- name: Run analyzer
run: flutter analyze

# building appbundle and APKs
- name: Build Android Appbundle
run: flutter build appbundle

- name: Build APKs for each abi
run: flutter build apk --split-per-abi --release

- name: Build Fat APK
run: flutter build apk --release

# release and upload to github
- name: Create a Release in GitHub
uses: ncipollo/release-action@v1
with:
artifacts: "build/app/outputs/apk/release/*.apk,build/app/outputs/bundle/release/app-release.aab"
token: ${{ secrets.TOKEN }}
commit: ${{ github.sha }}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A new Flutter project.

publish_to: "none" # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1
version: 99.99.99+99

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down

0 comments on commit 5c4e6ff

Please sign in to comment.