Skip to content

Commit

Permalink
chore: configure comment and release pipelines (#1154)
Browse files Browse the repository at this point in the history
  • Loading branch information
AsCress authored Jan 13, 2025
1 parent 74a463a commit 49e823b
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/actions/android/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,13 @@ runs:
VERSION_NAME: ${{inputs.VERSION_NAME}}
VERSION_CODE: ${{inputs.VERSION_CODE}}
run: |
flutter build apk --debug --build-name $VERSION_NAME --build-number $VERSION_CODE
flutter build apk --build-name $VERSION_NAME --build-number $VERSION_CODE
flutter build appbundle --build-name $VERSION_NAME --build-number $VERSION_CODE
- name: Store APK file
uses: actions/upload-artifact@v4
with:
name: apk-files
path: |
build/app/outputs/flutter-apk/app-debug.apk
10 changes: 10 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ jobs:
- name: Common Workflow
uses: ./.github/actions/common

- name: Save PR number
run: |
mkdir -p ./pr
echo ${{ github.event.number }} > ./pr/NR
- uses: actions/upload-artifact@v3
with:
name: pr
path: pr/

android:
name: Android Flutter Build
needs: common
Expand Down
128 changes: 128 additions & 0 deletions .github/workflows/pull_request_comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: Comment

on:
workflow_run:
workflows: [ Badge Magic PR CI ]
types:
- completed

jobs:
comment:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request'
steps:
- name: Download artifact
uses: actions/github-script@v7
with:
script: |
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr"
})[0];
var download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
- run: unzip pr.zip

- name: Build success
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: actions/github-script@v7
with:
script: |
var fs = require('fs')
var issue_number = Number(fs.readFileSync('./NR'));
const owner = context.repo.owner;
const repo = context.repo.repo;
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner,
repo,
run_id: ${{github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "apk-files"
})[0];
const artifact_url = `https://github.com/${owner}/${repo}/actions/runs/${{ github.event.workflow_run.id }}/artifacts/${matchArtifact.id}`;
const comments = await github.rest.issues.listComments({
owner,
repo,
issue_number
});
let comment_id;
for (const comment of comments.data) {
if (comment.user.login === 'github-actions[bot]') {
comment_id = comment.id;
break;
}
}
const body = `Build successful. APKs to test: ${artifact_url}`;
if (comment_id) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id,
body
});
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body
});
}
- name: Build failed
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
uses: actions/github-script@v7
with:
script: |
var fs = require('fs')
var issue_number = Number(fs.readFileSync('./NR'));
const owner = context.repo.owner;
const repo = context.repo.repo;
const comments = await github.rest.issues.listComments({
owner,
repo,
issue_number
});
let comment_id;
for (const comment of comments.data) {
if (comment.user.login === 'github-actions[bot]') {
comment_id = comment.id;
break;
}
}
const body = `Build failed`;
if (comment_id) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id,
body
});
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body
});
}
7 changes: 7 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,19 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Run Release Drafter
id: run-release-drafter
uses: release-drafter/release-drafter@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
version: ${{ needs.common.outputs.VERSION_NAME }}

- name: Create and Upload Assets
run: |
echo "${{ needs.common.outputs.VERSION_CODE }}" > ./versionCode.txt
git clone --branch=apk https://${{ github.repository_owner }}:${{ github.token }}@github.com/${{ github.repository }} apk
gh release upload ${{ steps.run-release-drafter.outputs.tag_name }} apk/badge-magic-flutter_app-release.apk ./versionCode.txt --clobber
screenshots:
name: Screenshots (Android)
runs-on: ubuntu-latest
Expand Down
61 changes: 61 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Release

on:
release:
types: [published]

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ANDROID_EMULATOR_API: 34
ANDROID_EMULATOR_ARCH: x86_64

jobs:
release:
if: ${{ github.repository == 'fossasia/badgemagic-app' }}
runs-on: ubuntu-latest

steps:
- name: Download repository
uses: actions/checkout@v4

- name: Download Assets
id: download-assets
run: |
gh release download ${{ github.event.release.tag_name }} --pattern '*.txt'
read -r version_code < versionCode.txt
echo "VERSION_CODE=$version_code" >> $GITHUB_OUTPUT
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Android Screenshot Workflow
uses: ./.github/actions/screenshot-android
with:
ANDROID_EMULATOR_API: ${{ env.ANDROID_EMULATOR_API }}
ANDROID_EMULATOR_ARCH: ${{ env.ANDROID_EMULATOR_ARCH }}

- name: Update Fastlane Metadata
run: |
cd ./android
git clone --branch=fastlane-android --depth=1 https://${{ github.repository_owner }}:${{ github.token }}@github.com/${{ github.repository }} fastlane
cd fastlane
echo "${{ github.event.release.body }}" > metadata/android/en-US/changelogs/${{ steps.download-assets.outputs.VERSION_CODE }}.txt
rm -rf metadata/android/en-US/images/phoneScreenshots/*
cp -r ../../screenshots/. metadata/android/en-US/images/phoneScreenshots/
# Force push to fastlane branch
git checkout --orphan temporary
git add --all .
git commit -am "[Auto] Update metadata for versionCode: ${{ steps.download-assets.outputs.VERSION_CODE }} ($(date +%Y-%m-%d.%H:%M:%S))"
git branch -D fastlane-android
git branch -m fastlane-android
git push --force origin fastlane-android
- name: Push version to production
run: |
fastlane promoteToProduction version_code:${{ steps.download-assets.outputs.VERSION_CODE }}
if [[ $? -ne 0 ]]; then
exit 1
fi

0 comments on commit 49e823b

Please sign in to comment.