-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: configure comment and release pipelines (#1154)
- Loading branch information
Showing
5 changed files
with
214 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
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 | ||
}); | ||
} |
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
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
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 |