diff --git a/.github/workflows/draft-release-flutter.yml b/.github/workflows/draft-release-flutter.yml new file mode 100644 index 0000000..b489d13 --- /dev/null +++ b/.github/workflows/draft-release-flutter.yml @@ -0,0 +1,109 @@ +name: draft release / flutter + +on: + workflow_call: + inputs: + slug: + description: Asset slug name + required: true + type: string + +permissions: + contents: write + +jobs: + create_draft_release: + name: create draft release + runs-on: ubuntu-latest + outputs: + upload_url: ${{ steps.gh_release.outputs.upload_url }} + url: ${{ steps.gh_release.outputs.url }} + steps: + - name: Checkout source code + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 + - id: gh_release + name: Create a new GitHub draft release + uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b + with: + draft: true + generate_release_notes: true + - name: Annotate workflow run with draft release URL + run: 'echo "### :shipit: Opened draft release for: [${{ inputs.slug }} ${{ github.ref_name }}](${{ steps.gh_release.outputs.url }})" >> "$GITHUB_STEP_SUMMARY"' + + upload_release_assets: + name: upload release assets + needs: + - create_draft_release + strategy: + fail-fast: false + matrix: + include: + - command: flutter build apk + - command: flutter build apk --split-per-abi + - command: flutter build appbundle + runs-on: ubuntu-latest + steps: + - name: Checkout source code + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 + - name: Set up Flutter + uses: subosito/flutter-action@fd55f4c5af5b953cc57a2be44cb082c8f6635e8e + with: + channel: stable + flutter-version-file: pubspec.yaml + cache: true + - name: Install dependencies + run: flutter pub get --enforce-lockfile + - name: Build release App Bundle + run: flutter build appbundle + - name: Build release APK + run: flutter build apk + - name: Stage assets + checksums + run: | + set -euo pipefail + + slug='${{ inputs.slug }}' + if [[ -z $slug ]]; then + echo "ERROR: inputs.slug is required and must be non-empty." >&2 + exit 2 + fi + + if [[ '${{ github.ref_type }}' != 'tag' ]]; then + echo "ERROR: This workflow must be invoked from a tag ref." >&2 + echo " ref_type='${{ github.ref_type }}' ref='${{ github.ref }}'" >&2 + exit 2 + fi + + tag='${{ github.ref_name }}' + if [[ -z $tag ]]; then + echo "ERROR: github.ref_name was empty; expected a tag name." >&2 + exit 2 + fi + + dist_dir="dist" + mkdir -p -- "$dist_dir" + + aab_src="build/app/outputs/bundle/release/app-release.aab" + apk_src="build/app/outputs/flutter-apk/app-release.apk" + [[ -f "$aab_src" ]] || { echo "ERROR: AAB not found at $aab_src" >&2; exit 2; } + [[ -f "$apk_src" ]] || { echo "ERROR: APK not found at $apk_src" >&2; exit 2; } + + aab_dst="${dist_dir}/${slug}-${tag}.aab" + apk_dst="${dist_dir}/${slug}-${tag}.apk" + + cp -v -- "$aab_src" "$aab_dst" + cp -v -- "$apk_src" "$apk_dst" + + pushd "$dist_dir" >/dev/null + sha256sum -- *.aab *.apk > sha256sums.txt + popd >/dev/null + + echo "Prepared assets:" + printf ' %s\n' "$apk_dst" "$aab_dst" "${dist_dir}/sha256sums.txt" + + - name: Uploading release assets + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + echo "Uploading assets to: ${{ needs.create_draft_release.outputs.upload_url }}" + gh release upload "$GITHUB_REF_NAME" dist/* --clobber + echo ":arrow_up: Uploaded release assets" >>"$GITHUB_STEP_SUMMARY"