Merge pull request #8 from mdddj/3.2.0 #3
This file contains 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: CI | |
env: | |
TZ: Asia/Shanghai | |
on: | |
push: | |
paths-ignore: | |
- '**/README.md' | |
- '.github/workflows/*' | |
- '!.github/workflows/main.yml' | |
pull_request: | |
paths-ignore: | |
- '**/README.md' | |
- '.github/workflows/*' | |
- '!.github/workflows/main.yml' | |
workflow_dispatch: | |
inputs: | |
debug_enabled: | |
type: boolean | |
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)' | |
required: false | |
default: false | |
jobs: | |
build_env: | |
name: build env | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: init custom env | |
run: | | |
set -a | |
BUILD_NAME="${GITHUB_REPOSITORY#*/}" | |
if [[ ${GITHUB_REF} == refs/tags/v* ]] | |
then | |
CREATE_RELEASE="true" | |
BUILD_VERSION=${GITHUB_REF#refs/tags/v} | |
if [[ -x ./latest-changelog.sh ]] | |
then | |
RELEASE_BODY=$(./latest-changelog.sh $BUILD_VERSION) | |
TG_CHANGELOG=$RELEASE_BODY | |
fi | |
if [[ -z "$RELEASE_BODY" ]] | |
then | |
RELEASE_BODY='### ${{ github.event.head_commit.message }}' | |
TG_CHANGELOG="$(echo "$RELEASE_BODY"|sed -n "s/### \(.*\)/\1/p" |sed -n '{;=;p}' | sed "N;s/\n/. /g")" | |
fi | |
elif [[ ${GITHUB_REF} == refs/pull* ]] | |
then | |
CREATE_RELEASE="false" | |
num=${GITHUB_REF#refs/pull/} | |
num=${num%/merge} | |
BUILD_VERSION=pr-${num}-"$(date +'%Y%m%d%H%M%S')" | |
elif [[ ${GITHUB_EVENT_NAME} == workflow_dispatch ]] | |
then | |
CREATE_RELEASE="false" | |
BUILD_VERSION="$(date +'%Y%m%d%H%M%S')" | |
elif [[ ${GITHUB_REF} == refs/heads* ]] | |
then | |
CREATE_RELEASE="false" | |
BUILD_VERSION="${GITHUB_REF#refs/heads/}-$(date +'%Y%m%d%H%M%S')" | |
RELEASE_BODY=$(echo '${{ toJson(github.event.commits) }}' |jq -r 'map("### "+.message)|join("\n\n------\n")') | |
TG_CHANGELOG="$(echo "$RELEASE_BODY"|sed -n "s/### \(.*\)/\1/p" |sed -n '{;=;p}' | sed "N;s/\n/. /g")" | |
VERSION_PREFIX='内测版-' | |
else | |
CREATE_RELEASE="false" | |
BUILD_VERSION="$(date +'%Y%m%d%H%M%S')" | |
fi | |
BUILD_NAME_WITH_VERSION="$BUILD_NAME-$BUILD_VERSION" | |
echo BUILD_NAME="$BUILD_NAME" >> .custom_env | |
echo BUILD_VERSION="$BUILD_VERSION" >> .custom_env | |
echo BUILD_NAME_WITH_VERSION="$BUILD_NAME_WITH_VERSION" >> .custom_env | |
echo CREATE_RELEASE="$CREATE_RELEASE" >> .custom_env | |
if test -n "$RELEASE_BODY" | |
then | |
echo 'RELEASE_BODY<<EOF' >> .custom_env | |
echo "$RELEASE_BODY" >> .custom_env | |
echo 'EOF' >> .custom_env | |
if [ -f template-update.md ] | |
then | |
echo 'UPDATE_BODY<<EOF' >> .custom_env | |
envsubst < template-update.md >> .custom_env | |
echo >> .custom_env | |
echo 'EOF' >> .custom_env | |
fi | |
fi | |
echo DEPLOY_WEB="true" >> .custom_env | |
if [[ "$CREATE_RELEASE" == "true" && -n "${{ secrets.TELEGRAM_TO }}" && -n "${{ secrets.TELEGRAM_TOKEN }}" ]] | |
then | |
echo SEND_TELEGRAM="true" >> .custom_env | |
fi | |
cat .custom_env | |
cat .custom_env >> $GITHUB_ENV | |
- name: upload .custom_env | |
uses: actions/upload-artifact@v4 | |
with: | |
name: custom_env | |
path: ./.custom_env | |
- name: Setup tmate session | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
uses: mxschmitt/action-tmate@v3 | |
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }} | |
- name: clean custom env | |
run: rm .custom_env | |
build_app: | |
needs: [ build_env ] | |
name: Build Flutter (${{ matrix.config }}) | |
runs-on: ${{ matrix.os }} | |
env: | |
APP_DIR: example | |
strategy: | |
matrix: | |
name: [ android, android-aab, web, linux, windows, ios, macos ] | |
include: | |
- name: android | |
config: apk | |
os: ubuntu-latest | |
FILE_TYPE: apk | |
BUILD_ARGS: "--target-platform android-arm64" | |
RELEASE_PATH: '*.apk' | |
RELEASE_DIRECTORY: build/app/outputs/apk/release | |
- name: android-aab | |
config: appbundle | |
os: ubuntu-latest | |
FILE_TYPE: aab | |
BUILD_ARGS: "" | |
RELEASE_PATH: '*.aab' | |
RELEASE_DIRECTORY: build/app/outputs/bundle/release | |
- name: web | |
config: web | |
os: ubuntu-latest | |
FILE_TYPE: zip | |
RELEASE_PATH: . | |
RELEASE_DIRECTORY: build/web | |
- name: linux | |
config: linux | |
os: ubuntu-latest | |
FILE_TYPE: tar.gz | |
ENABLE_CONFIG: linux-desktop | |
RELEASE_PATH: . | |
RELEASE_DIRECTORY: build/linux/x64/release/bundle | |
PRE_COMMAND: | | |
sudo apt-get -y update | |
sudo apt-get -y install clang cmake git ninja-build pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev | |
- name: windows | |
config: windows | |
os: windows-latest | |
FILE_TYPE: zip | |
RELEASE_PATH: . | |
RELEASE_DIRECTORY: build/windows/x64/runner/Release | |
- name: ios | |
config: ios | |
os: macos-latest | |
FILE_TYPE: ipa | |
BUILD_ARGS: "--no-codesign" | |
RELEASE_PATH: Payload | |
RELEASE_DIRECTORY: build/ios/iphoneos | |
POST_COMMAND: | | |
cd build/ios/iphoneos | |
mkdir Payload | |
cd Payload | |
ln -s ../Runner.app | |
- name: macos | |
config: macos | |
os: macos-latest | |
FILE_TYPE: dmg | |
ENABLE_CONFIG: macos-desktop | |
RELEASE_PATH: "*.app" | |
RELEASE_DIRECTORY: build/macos/Build/Products/Release | |
# Disable fail-fast; we want results from all OSes even if one fails. | |
fail-fast: false | |
steps: | |
- name: download custom env | |
uses: actions/download-artifact@v4 | |
with: | |
name: custom_env | |
- name: apply custom env | |
if: startsWith(matrix.os, 'windows') != true | |
run: | | |
cat .custom_env >> $GITHUB_ENV | |
rm .custom_env | |
- name: apply custom env - Windows | |
if: startsWith(matrix.os, 'windows') | |
run: | | |
type .custom_env >> $env:GITHUB_ENV | |
del .custom_env | |
- uses: actions/checkout@v4 | |
- uses: subosito/flutter-action@v2 | |
with: | |
channel: 'stable' | |
- name: pre | |
run: ${{ matrix.PRE_COMMAND }} | |
- name: enable config (${{ matrix.config }}) | |
if: "${{ matrix.ENABLE_CONFIG != '' }}" | |
run: flutter config --enable-${{ matrix.ENABLE_CONFIG }} | |
- name: prepare android signing key | |
env: | |
SIGNING_KEY: ${{ secrets.SIGNING_KEY }} | |
if: "${{ ( matrix.FILE_TYPE == 'apk' || matrix.FILE_TYPE == 'aab' ) && env.SIGNING_KEY != '' }}" | |
run: | | |
cd ${{ env.APP_DIR }}/android | |
echo "${{ secrets.SIGNING_KEY }}" |base64 -d > ci.jks | |
echo storeFile=ci.jks > key.properties | |
echo storePassword=${{ secrets.KEY_STORE_PASSWORD }} >> key.properties | |
echo keyAlias=${{ secrets.ALIAS }} >> key.properties | |
echo keyPassword=${{ secrets.KEY_PASSWORD }} >> key.properties | |
- name: build | |
run: | | |
mkdir build | |
dart pub global activate melos | |
melos bootstrap | |
cd ${{ env.APP_DIR }} | |
flutter build ${{ matrix.config }} ${{ matrix.BUILD_ARGS }} | |
- name: post | |
run: | | |
cd ${{ env.APP_DIR }}/ | |
${{ matrix.POST_COMMAND }} | |
- name: cname | |
env: | |
CNAME: ${{ secrets.CNAME }} | |
if: "${{ matrix.name == 'web' && env.CNAME != '' }}" | |
run: echo ${{ env.CNAME }} > ${{ env.APP_DIR }}/${{ matrix.RELEASE_DIRECTORY }}/${{ matrix.RELEASE_PATH }}/CNAME | |
- name: tar.gz | |
if: "${{ matrix.FILE_TYPE == 'tar.gz' }}" | |
uses: thedoctor0/zip-release@master | |
with: | |
type: tar | |
path: ${{ matrix.RELEASE_PATH }} | |
directory: ${{ env.APP_DIR }}/${{ matrix.RELEASE_DIRECTORY }} | |
filename: ${{ github.workspace }}/build/${{ env.BUILD_NAME_WITH_VERSION }}-${{ matrix.name }}.${{ matrix.FILE_TYPE }} | |
- name: zip | |
if: "${{ matrix.FILE_TYPE == 'zip' || matrix.FILE_TYPE == 'ipa' }}" | |
uses: thedoctor0/zip-release@master | |
with: | |
type: zip | |
path: ${{ matrix.RELEASE_PATH }} | |
directory: ${{ env.APP_DIR }}/${{ matrix.RELEASE_DIRECTORY }} | |
filename: ${{ github.workspace }}/build/${{ env.BUILD_NAME_WITH_VERSION }}-${{ matrix.name }}.${{ matrix.FILE_TYPE }} | |
- name: set python version | |
if: "${{ matrix.FILE_TYPE == 'dmg' }}" | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.11' | |
- name: dmg | |
if: "${{ matrix.FILE_TYPE == 'dmg' }}" | |
run: | | |
npm install -g appdmg | |
appPath=$(ls -d ${{ env.APP_DIR }}/${{ matrix.RELEASE_DIRECTORY }}/${{ matrix.RELEASE_PATH }}) | |
echo '{"title":"###TITLE###","icon":"###PATH###/Contents/Resources/AppIcon.icns","contents":[{"x":448,"y":144,"type":"link","path":"/Applications"},{"x":192,"y":144,"type":"file","path":"###PATH###"}]}' | | |
sed "s/###TITLE###/${{ env.BUILD_NAME }}/g" | | |
sed "s/###PATH###/$(echo $appPath | sed 's_/_\\/_g')/g" | | |
tee ./appdmg.json | |
appdmg ./appdmg.json build/${{ env.BUILD_NAME_WITH_VERSION }}-${{ matrix.name }}.${{ matrix.FILE_TYPE }} | |
- name: copy file | |
if: "${{ matrix.FILE_TYPE == 'apk' || matrix.FILE_TYPE == 'aab' }}" | |
run: cp ${{ env.APP_DIR }}/${{ matrix.RELEASE_DIRECTORY }}/${{ matrix.RELEASE_PATH }} build/${{ env.BUILD_NAME_WITH_VERSION }}-${{ matrix.name }}.${{ matrix.FILE_TYPE }} | |
- name: Archive Production Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.name }}-build | |
path: build/${{ env.BUILD_NAME_WITH_VERSION }}-${{ matrix.name }}.${{ matrix.FILE_TYPE }} | |
- name: Deploy | |
if: "${{ matrix.name == 'web' && env.DEPLOY_WEB == 'true' }}" | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
force_orphan: true | |
publish_dir: ${{ env.APP_DIR }}/${{ matrix.RELEASE_DIRECTORY }}/${{ matrix.RELEASE_PATH }} | |
release_create: | |
needs: [ build_app ] | |
name: create release | |
runs-on: ubuntu-latest | |
steps: | |
- name: download custom env | |
uses: actions/download-artifact@v4 | |
with: | |
name: custom_env | |
- name: apply custom env | |
run: | | |
cat .custom_env >> $GITHUB_ENV | |
rm .custom_env | |
- name: create release | |
if: ${{ env.CREATE_RELEASE == 'true' }} | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: v${{ env.BUILD_VERSION }} | |
release_name: v${{ env.BUILD_VERSION }} | |
body: ${{ env.RELEASE_BODY }} | |
draft: true | |
prerelease: ${{ env.PRE_RELEASE == 'true' }} | |
- name: save release env | |
if: ${{ env.CREATE_RELEASE == 'true' }} | |
run: | | |
echo RELEASE_UPLAOD_URL="${{ steps.create_release.outputs.upload_url }}" >> .release_env | |
echo RELEASE_UPLAOD_ID="${{ steps.create_release.outputs.id }}" >> .release_env | |
- name: upload .release_env | |
if: ${{ env.CREATE_RELEASE == 'true' }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: release_env | |
path: ./.release_env | |
release_upload: | |
needs: [ release_create ] | |
name: upload release file | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
name: [ android, android-aab, web, linux, windows, ios, macos ] | |
include: | |
- name: android | |
FILE_TYPE: apk | |
- name: android-aab | |
FILE_TYPE: aab | |
- name: web | |
FILE_TYPE: zip | |
- name: linux | |
FILE_TYPE: tar.gz | |
- name: windows | |
FILE_TYPE: zip | |
- name: ios | |
FILE_TYPE: ipa | |
- name: macos | |
FILE_TYPE: dmg | |
# Disable fail-fast; we want results from all OSes even if one fails. | |
fail-fast: false | |
steps: | |
- name: download custom env | |
uses: actions/download-artifact@v4 | |
with: | |
name: custom_env | |
- name: apply custom env | |
run: | | |
cat .custom_env >> $GITHUB_ENV | |
rm .custom_env | |
- name: download release env | |
if: ${{ env.CREATE_RELEASE == 'true' }} | |
uses: actions/download-artifact@v4 | |
with: | |
name: release_env | |
- name: apply release env | |
if: ${{ env.CREATE_RELEASE == 'true' }} | |
run: | | |
cat .release_env >> $GITHUB_ENV | |
rm .release_env | |
- name: download (${{ matrix.name }}) | |
if: ${{ env.CREATE_RELEASE == 'true' }} | |
uses: actions/download-artifact@v4 | |
with: | |
name: ${{ matrix.name }}-build | |
- name: Upload Release Asset (${{ matrix.name }}) | |
if: ${{ env.CREATE_RELEASE == 'true' }} | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ env.RELEASE_UPLAOD_URL }} | |
asset_path: ${{ env.BUILD_NAME_WITH_VERSION }}-${{ matrix.name }}.${{ matrix.FILE_TYPE }} | |
asset_name: ${{ env.BUILD_NAME_WITH_VERSION }}-${{ matrix.name }}.${{ matrix.FILE_TYPE }} | |
asset_content_type: application/zip | |
release_publish: | |
needs: [ release_upload ] | |
name: publish release | |
runs-on: ubuntu-latest | |
steps: | |
- name: download custom env | |
uses: actions/download-artifact@v4 | |
with: | |
name: custom_env | |
- name: apply custom env | |
run: | | |
cat .custom_env >> $GITHUB_ENV | |
rm .custom_env | |
- name: download release env | |
if: ${{ env.CREATE_RELEASE == 'true' }} | |
uses: actions/download-artifact@v4 | |
with: | |
name: release_env | |
- name: apply release env | |
if: ${{ env.CREATE_RELEASE == 'true' }} | |
run: | | |
cat .release_env >> $GITHUB_ENV | |
rm .release_env | |
- name: publish release | |
if: ${{ env.CREATE_RELEASE == 'true' }} | |
uses: eregon/publish-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
release_id: ${{ env.RELEASE_UPLAOD_ID }} | |
pub_dev_publish: | |
needs: [ release_publish ] | |
name: publish packages | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write # This is required for requesting the JWT | |
steps: | |
- name: download custom env | |
uses: actions/download-artifact@v4 | |
with: | |
name: custom_env | |
- name: apply custom env | |
run: | | |
cat .custom_env >> $GITHUB_ENV | |
rm .custom_env | |
- uses: actions/checkout@v4 | |
- uses: subosito/flutter-action@v2 | |
with: | |
channel: "stable" | |
- name: 'Installs the Dart SDK and sets up the pipeline for usage with pub.dev (this sets up OIDC)' | |
uses: dart-lang/setup-dart@v1 | |
- run: ./script/prepare.sh | |
- name: publish dry run | |
if: ${{ env.CREATE_RELEASE != 'true' }} | |
run: ./script/publish_dry_run.sh | |
- name: publish package | |
if: ${{ env.CREATE_RELEASE == 'true' }} | |
run: ./script/publish.sh |