Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 51 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ jobs:
go-version-file: native/go.mod
cache-dependency-path: native/go.sum

- name: Set up Ruby and Fastlane
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.4.10"
bundler-cache: true

- name: Run native tests with the race detector
working-directory: native
run: go test -race ./...
run: bundle exec fastlane android native_tests

android-tests:
name: Android tests and checks
Expand All @@ -53,6 +58,12 @@ jobs:
go-version-file: native/go.mod
cache-dependency-path: native/go.sum

- name: Set up Ruby and Fastlane
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.4.10"
bundler-cache: true

- name: Install Android SDK components
run: |
sdkmanager="$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager"
Expand All @@ -67,8 +78,42 @@ jobs:
"ndk;29.0.14206865"
echo "ANDROID_NDK_HOME=$ANDROID_HOME/ndk/29.0.14206865" >> "$GITHUB_ENV"

- name: Build native library using the F-Droid recipe
run: ./scripts/build-fdroid-native.sh
- name: Run Android checks and verify the unsigned APK
run: bundle exec fastlane android android_checks

- name: Run Android tests, checks, and clean-store builds
run: ./gradlew --no-daemon testDebugUnitTest lintDebug assembleDebug assembleRelease
- name: Publish PR debug APK
if: github.event_name == 'pull_request'
id: debug_apk_upload
uses: actions/upload-artifact@v7
with:
name: megaproxy-pr-${{ github.event.pull_request.number }}-debug-apk
path: app/build/outputs/apk/debug/app-debug.apk
if-no-files-found: error
compression-level: 0
retention-days: 14

- name: Publish PR unsigned release APK
if: github.event_name == 'pull_request'
id: unsigned_release_apk_upload
uses: actions/upload-artifact@v7
with:
name: megaproxy-pr-${{ github.event.pull_request.number }}-unsigned-release-apk
path: app/build/outputs/apk/release/app-release-unsigned.apk
if-no-files-found: error
compression-level: 0
retention-days: 14

- name: Add APK download links to the job summary
if: github.event_name == 'pull_request'
env:
DEBUG_APK_URL: ${{ steps.debug_apk_upload.outputs.artifact-url }}
UNSIGNED_RELEASE_APK_URL: ${{ steps.unsigned_release_apk_upload.outputs.artifact-url }}
run: |
{
echo "## APK artifacts"
echo
echo "- [Download debug APK]($DEBUG_APK_URL) — signed with the disposable Android debug key"
echo "- [Download unsigned release APK]($UNSIGNED_RELEASE_APK_URL) — verified unsigned"
echo
echo "Artifacts expire after 14 days. Neither APK uses the MegaProxy release key."
} >> "$GITHUB_STEP_SUMMARY"
101 changes: 101 additions & 0 deletions .github/workflows/pr-artifacts-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: PR artifact links

on:
workflow_run:
workflows:
- CI
types:
- completed

permissions:
actions: read
contents: read
pull-requests: write

jobs:
comment:
name: Add APK links to the pull request
if: >-
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'pull_request'
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Create or update the APK artifact comment
uses: actions/github-script@v9
with:
script: |
const run = context.payload.workflow_run;
const pullRequests = run.pull_requests || [];

if (pullRequests.length !== 1) {
core.notice(`Expected one pull request for workflow run ${run.id}, found ${pullRequests.length}`);
return;
}

const pullNumber = pullRequests[0].number;
const expectedArtifacts = {
debug: `megaproxy-pr-${pullNumber}-debug-apk`,
release: `megaproxy-pr-${pullNumber}-unsigned-release-apk`,
};
const artifacts = await github.paginate(
github.rest.actions.listWorkflowRunArtifacts,
{
owner: context.repo.owner,
repo: context.repo.repo,
run_id: run.id,
per_page: 100,
}
);

const findArtifact = (name) => artifacts.find(
(artifact) => artifact.name === name && !artifact.expired
);
const debugArtifact = findArtifact(expectedArtifacts.debug);
const releaseArtifact = findArtifact(expectedArtifacts.release);

if (!debugArtifact || !releaseArtifact) {
core.setFailed(`Expected APK artifacts were not found for workflow run ${run.id}`);
return;
}

const artifactUrl = (artifact) =>
`${context.serverUrl}/${context.repo.owner}/${context.repo.repo}` +
`/actions/runs/${run.id}/artifacts/${artifact.id}`;
const marker = '<!-- megaproxy-pr-apks -->';
const body = [
marker,
'## APK artifacts',
'',
`- [Download debug APK](${artifactUrl(debugArtifact)}) — signed with the disposable Android debug key`,
`- [Download unsigned release APK](${artifactUrl(releaseArtifact)}) — verified unsigned`,
'',
`Built from commit \`${run.head_sha.slice(0, 8)}\` by [CI run #${run.run_number}](${run.html_url}).`,
'Artifacts expire after 14 days. Neither APK uses the MegaProxy release key.',
].join('\n');

const comments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pullNumber,
per_page: 100,
});
const previousComment = comments.find(
(comment) => comment.user.type === 'Bot' && comment.body.includes(marker)
);

if (previousComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: previousComment.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pullNumber,
body,
});
}
17 changes: 8 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ jobs:
go-version-file: native/go.mod
cache-dependency-path: native/go.sum

- name: Set up Ruby and Fastlane
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.4.10"
bundler-cache: true

- name: Install Android SDK components
run: |
sdkmanager="$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager"
Expand Down Expand Up @@ -81,19 +87,12 @@ jobs:
echo "MEGAPROXY_KEYSTORE_PATH=$keystore" >> "$GITHUB_ENV"
echo "MEGAPROXY_KEY_PASSWORD_FILE=$password_file" >> "$GITHUB_ENV"

- name: Build optimized signed APKs
env:
MEGAPROXY_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
MEGAPROXY_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
MEGAPROXY_GIT_COMMIT: ${{ github.sha }}
run: ./scripts/build-release-apks.sh

- name: Build signed App Bundle
- name: Build and verify signed release artifacts
env:
MEGAPROXY_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
MEGAPROXY_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
MEGAPROXY_GIT_COMMIT: ${{ github.sha }}
run: ./scripts/build-release-bundle.sh
run: bundle exec fastlane android release_artifacts

- name: Publish GitHub Release
env:
Expand Down
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.4.10
20 changes: 6 additions & 14 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,21 @@
{
"label": "Test: Go core",
"type": "shell",
"command": "source \"$HOME/.zshrc.extra\"; go test ./...",
"options": {
"cwd": "${workspaceFolder}/native"
},
"command": "source \"$HOME/.zshrc.extra\"; bundle exec fastlane android native_tests",
"group": "test",
"problemMatcher": []
},
{
"label": "Test: Android unit tests",
"label": "Test: Android checks",
"type": "shell",
"command": "source \"$HOME/.zshrc.extra\"; ./gradlew testDebugUnitTest",
"command": "source \"$HOME/.zshrc.extra\"; bundle exec fastlane android android_checks",
"group": "test",
"problemMatcher": []
},
{
"label": "Test: All",
"dependsOn": [
"Test: Go core",
"Test: Android unit tests"
],
"dependsOrder": "parallel",
"type": "shell",
"command": "source \"$HOME/.zshrc.extra\"; bundle exec fastlane android test",
"group": {
"kind": "test",
"isDefault": true
Expand All @@ -76,9 +70,7 @@
{
"label": "Android: Build debug APK",
"type": "shell",
"command": "source \"$HOME/.zshrc.extra\"; ./gradlew assembleDebug",
"dependsOn": ["Android: Build native AAR"],
"dependsOrder": "sequence",
"command": "source \"$HOME/.zshrc.extra\"; bundle exec fastlane android debug_artifact",
"group": {
"kind": "build",
"isDefault": true
Expand Down
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "https://rubygems.org"

gem "fastlane", "2.238.0"
Loading