Skip to content

Medication Functionality [WIP] #56

Medication Functionality [WIP]

Medication Functionality [WIP] #56

Workflow file for this run

name: Deploy
on:
pull_request:
branches: [ "main" ]
env:
# Setup env variables
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
JAVA_VERSION: 17
DISTRIBUTION: zulu
KEYSTORE_PATH: android/circle-keystore.jks
KEY_PROPERTIES_PATH: android/key.properties
AAB_PATH: build/app/outputs/bundle/release/app-release.aab
APK_PATH: build/app/outputs/flutter-apk/app-release.apk
RELEASE_NOTES_PATH: distribution/release_notes/release_notes.md
SERVICE_ACCOUNT_KEY_PATH: android/circle-60af7-f47644410c6a.json
RELEASE_TRACK: internal
PACKAGE_NAME: co.circleapp.app
FLUTTER_CHANNEL: main
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
jobs:
version:
if: github.event_name == 'pull_request' && startsWith(github.head_ref, 'release')
permissions:
contents: write
name: Update Version Number
runs-on: ubuntu-latest
outputs:
new_full_version: ${{ steps.increment_version.outputs.new_full_version }}
release_name: ${{ steps.increment_version.outputs.release_name }}
semantic_version: ${{ steps.increment_version.outputs.semantic_version }}
new_build_number: ${{ steps.increment_version.outputs.new_build_number }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ env.BRANCH_NAME }}
# Get current version number
- name: Get Current Version number
id: version_number
run: |
FULL_VERSION=$(grep 'version:' pubspec.yaml | cut -d' ' -f2)
SEMANTIC_VERSION=$(echo $FULL_VERSION | cut -d'+' -f1)
BUILD_NUMBER=$(echo $FULL_VERSION | cut -d'+' -f2)
echo "full_version=$FULL_VERSION" >> $GITHUB_OUTPUT
echo "semantic_version=$SEMANTIC_VERSION" >> $GITHUB_OUTPUT
echo "current_build_number=$BUILD_NUMBER" >> $GITHUB_OUTPUT
# Increment build number and version
- name: Increment build number
id: increment_version
run: |
NEW_BUILD_NUMBER=$((${{ steps.version_number.outputs.current_build_number }} +1 ))
NEW_FULL_VERSION="${{ steps.version_number.outputs.semantic_version }}+$NEW_BUILD_NUMBER"
SEMANTIC_VERSION="${{ steps.version_number.outputs.semantic_version }}"
RELEASE_NAME="$NEW_BUILD_NUMBER($SEMANTIC_VERSION)"
# Update version in pubspec.yaml
sed -i "s/version: \(.*\)/version: $NEW_FULL_VERSION/" pubspec.yaml
# Outputting relevant Env vars
echo "new_full_version=$NEW_FULL_VERSION" >> $GITHUB_OUTPUT
echo "semantic_version=$SEMANTIC_VERSION" >> $GITHUB_OUTPUT
echo "new_build_number=$NEW_BUILD_NUMBER" >> $GITHUB_OUTPUT
echo "release_name=$RELEASE_NAME" >> $GITHUB_OUTPUT
# Commit updated version number
- name: Commit Changes
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "Github Actions[bot]"
git add pubspec.yaml
echo "Committing version: ${{ steps.increment_version.outputs.new_full_version }}"
git commit -m "ci: increment version to ${{ steps.increment_version.outputs.new_full_version }} [skip ci]"
# Push and tag commit
- name: Push changes and tag
run: |
# Debug info
echo "Pushing to branch: $BRANCH_NAME"
echo "Repository: ${{ github.repository }}"
# Make sure we're up to date
git fetch origin || { echo "Failed to fetch origin"; exit 1; }
git pull --rebase origin "$BRANCH_NAME" || { echo "Failed to pull/rebase"; exit 1; }
# Push changes with more verbose output
git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} HEAD:"$BRANCH_NAME" 2>&1 || {
echo "Failed to push changes";
echo "Git remote -v output:";
git remote -v;
exit 1;
}
# Create and push tag with verbose output
git tag "v${{ steps.increment_version.outputs.new_full_version }}"
git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} "v${{ steps.increment_version.outputs.new_full_version }}" 2>&1 || {
echo "Failed to push tag";
exit 1;
}
deploy:
# Only run this workflow if the branch name starts with 'release'
if: startsWith(github.head_ref, 'release')
needs: version
name: Deploy Release to Google Play Store
runs-on: ubuntu-latest
# Add the relevant outputs from the 'version' job to env vars
env:
NEW_FULL_VERSION: ${{ needs.version.outputs.new_full_version }}
RELEASE_NAME: ${{ needs.version.outputs.release_name }}
SEMANTIC_VERSION: ${{ needs.version.outputs.semantic_version }}
NEW_BUILD_NUMBER: ${{ needs.version.outputs.new_build_number }}
permissions:
contents: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ env.BRANCH_NAME }} # Checkout the release branch with updated version number
- name: Echo New Versions
run: |
echo "New version: ${{ env.NEW_FULL_VERSION }}"
echo "New release name: ${{ env.RELEASE_NAME }}"
echo "New semantic version: ${{ env.SEMANTIC_VERSION }}"
echo "New build number: ${{ env.NEW_BUILD_NUMBER }}"
# Authenticate to Google Cloud Platform
# - id: auth
# name: Authenticate to Google Cloud Platform
# uses: google-github-actions/auth@v2
#
# with:
# workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
# service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}
# Set up JDK 17
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: ${{ env.DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
# Setup Flutter
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: ${{ env.FLUTTER_CHANNEL }}
# Decode Android Secrets
- name: Decode Android Keystore
run: echo "${{ secrets.ANDROID_KEYSTORE }}" | base64 --decode > ${{ env.KEYSTORE_PATH }}
- name: Decode Android key.properties
run: echo "${{ secrets.ANDROID_KEY_PROPERTIES }}" | base64 --decode > ${{ env.KEY_PROPERTIES_PATH }}
- name: Decode GCP Service Account Key
run: echo "${{ secrets.GCP_CIRCLE_SERVICE_ACCOUNT_KEY }}" | base64 --decode > ${{ env.SERVICE_ACCOUNT_KEY_PATH }}
# Build Android APK and AppBundle application
- run: flutter --version
- run: flutter pub get
- name: Build AppBundle and APK
run: |
flutter build appbundle --release
flutter build apk --release
# Create a Release in Github with the updated version from the `version` job
- name: Create Release in Github
id: create_release
uses: ncipollo/release-action@v1
with:
artifacts: ${{ env.AAB_PATH }}, ${{ env.APK_PATH }}
token: ${{ secrets.GITHUB_TOKEN }}
tag: "v${{ env.NEW_FULL_VERSION }}" # Uses the new version from the `version` job
commit: ${{ github.sha }}
bodyFile: ${{ env.RELEASE_NOTES_PATH }}
generateReleaseNotes: true
# Upload Generate aab to artifacts
- name: Upload AAB and APK to artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts
path: |
${{ env.AAB_PATH }}
${{ env.APK_PATH }}
# Deploy Bundle to Google Play Store
- name: Deploy to Google Play Store
uses: r0adkll/upload-google-play@v1
with:
# serviceAccountJson: ${{ steps.auth.outputs.credentials_file_path }} #Uses the google account credentials from the earlier Workload Identity Provider
serviceAccountJson: ${{ env.SERVICE_ACCOUNT_KEY_PATH }} #Uses generated Service Account Key
track: ${{ env.RELEASE_TRACK }}
packageName: ${{ env.PACKAGE_NAME }}
releaseFiles: ${{ env.AAB_PATH }}
whatsNewDirectory: distribution/whats_new
status: draft
releaseName: ${{ env.RELEASE_NAME }}