Skip to content

push@gradle : no comment #66

push@gradle : no comment

push@gradle : no comment #66

name: Build, Deploy, and APK
on:
push:
branches: ["gradle"]
workflow_dispatch:
permissions:
contents: write
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
check-keystore:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check if KEYSTORE_FILE secret is empty
run: |
if [ -z "${{ secrets.KEYSTORE_FILE }}" ]; then
echo "Keystore secret is empty. Exiting..."
exit 1
fi
- name: Restore Keystore
run: |
echo "${{ secrets.KEYSTORE_FILE }}" | base64 --decode > mg-build-release-key.keystore
- name: Verify Keystore File Size
run: |
if [ ! -s mg-build-release-key.keystore ]; then
echo "Keystore file is empty. Exiting..."
exit 1
fi
- name: List Keystore Contents
run: |
keytool -list -v -keystore mg-build-release-key.keystore -storepass "${{ secrets.KEYSTORE_PASSWORD }}"
env:
JAVA_HOME: /usr/lib/jvm/java-11-openjdk-amd64
- name: Clean up
run: rm -f mg-build-release-key.keystore # Use -f to avoid errors if the file doesn't exist
build:
runs-on: ubuntu-latest
env:
HUGO_VERSION: 0.128.0
steps:
- name: Install Hugo CLI
run: |
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb
- name: Install Dart Sass
run: sudo snap install dart-sass
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup Pages
id: pages
uses: actions/configure-pages@v5
- name: Install Node.js dependencies
run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"
- name: Build with Hugo
env:
HUGO_CACHEDIR: ${{ runner.temp }}/hugo_cache
HUGO_ENVIRONMENT: production
run: hugo --minify --baseURL "${{ steps.pages.outputs.base_url }}/"
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./gradle/public
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
build-apk:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Restore Keystore
run: |
echo "${{ secrets.KEYSTORE_FILE }}" | base64 --decode > mg-build-release-key.keystore
- name: Verify Keystore File Size
run: |
if [ ! -s mg-build-release-key.keystore ]; then
echo "Keystore file is empty or not restored. Exiting..."
exit 1
fi
- name: Copy Keystore to Correct Location
run: |
cp mg-build-release-key.keystore "${GITHUB_WORKSPACE}/cordovaProject/key/mg-build-release-key.keystore"
- name: Build APK using Docker
run: |
REPO_URL="${{ github.event.repository.html_url }}"
REPO_NAME=$(basename -s .git "$REPO_URL")
APP_NAME=$(echo "$REPO_NAME" | sed -e 's/-/ /g' -e 's/^./\U&/')
PACKAGE_NAME=$(echo "$REPO_URL" | sed 's|https://github.com/||;s|/|.|g;s|.git$||;s|-|.|g;s|[^a-zA-Z0-9.]||g')
docker run --rm -v "${{ github.workspace }}:/github/workspace" -w /github/workspace mobagenie/mgbuild:v1 sh -c "
sed -i 's/appNameReplace/$APP_NAME/g; s/appDescReplace/$APP_NAME/g' cordovaProject/config.xml &&
sed -i 's/pkgNameReplace/$PACKAGE_NAME/g; s/displayNameReplace/$APP_NAME/g; s/appDescReplace/$APP_NAME/g' cordovaProject/package.json &&
cp -r gradle/public/* cordovaProject/www &&
cd cordovaProject &&
cordova platform add android &&
cordova build android --release -- --packageType=apk --keystore=key/mg-build-release-key.keystore --storePassword=${{ secrets.KEYSTORE_PASSWORD }} --alias=${{ secrets.KEY_ALIAS }} --password=${{ secrets.KEY_PASSWORD }} --keystoreType=jks"
- name: Archive APKs
run: |
REPO_URL="${{ github.event.repository.html_url }}"
REPO_NAME=$(basename -s .git "$REPO_URL")
APP_NAME=$(echo "$REPO_NAME" | sed -e 's/-/ /g' -e 's/^./\U&/')
PACKAGE_NAME=$(echo "$REPO_URL" | sed 's|https://github.com/||;s|/|.|g;s|.git$||;s|-|.|g;s|[^a-zA-Z0-9.]||g')
mkdir -p apk
cp -r cordovaProject/platforms/android/app/build/outputs/apk/release/*.apk apk/
echo "APK files in apk directory:"
ls apk
- name: Set tag and release name
id: set_release_info
run: |
TAG_NAME="release-$(echo $GITHUB_SHA | cut -c1-7)"
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
echo "RELEASE_NAME=Release $(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_ENV
- name: Create asset name
id: create_asset_name
run: |
REPO_URL="${{ github.event.repository.html_url }}"
REPO_NAME=$(basename -s .git "$REPO_URL")
APP_NAME=$(echo "$REPO_NAME" | sed -e 's/-/ /g' -e 's/^./\U&/')
PACKAGE_NAME=$(echo "$REPO_URL" | sed 's|https://github.com/||;s|/|.|g;s|.git$||;s|-|.|g;s|[^a-zA-Z0-9.]||g')
echo "ASSET_NAME=com.${PACKAGE_NAME}-$(echo $GITHUB_SHA | cut -c1-7).apk" >> $GITHUB_ENV
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
with:
tag_name: ${{ env.TAG_NAME }}
release_name: ${{ env.RELEASE_NAME }}
body: "APK build for gradle branch"
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload APK to Release
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: apk/app-release.apk # Ensure this matches the APK filename
asset_name: ${{ env.ASSET_NAME }} # Reference the asset name here
asset_content_type: application/vnd.android.package-archive
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Clean up Keystore
run: rm -f mg-build-release-key.keystore # Use -f to avoid errors if the file doesn't exist