Build #98
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: Build | |
on: | |
schedule: | |
- cron: '48 9 * * 4' | |
pull_request: | |
branches: | |
- "main" | |
push: | |
branches: | |
- "main" | |
paths-ignore: | |
- ".github/workflows/**" | |
workflow_dispatch: | |
inputs: {} | |
env: | |
main_app_folder_path: src/App | |
main_app_project_path: src/App/App.csproj | |
target-net-version: net8.0 | |
jobs: | |
cloc: | |
name: CLOC | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
- name: Set up CLOC | |
run: | | |
sudo apt-get update | |
sudo apt-get -y install cloc | |
- name: Print lines of code | |
run: cloc --vcs git --exclude-dir Resources,store,test,Properties --include-lang C#,XAML | |
setup: | |
name: Setup | |
runs-on: ubuntu-22.04 | |
outputs: | |
rc_branch_exists: ${{ steps.branch-check.outputs.rc_branch_exists }} | |
hotfix_branch_exists: ${{ steps.branch-check.outputs.hotfix_branch_exists }} | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
with: | |
submodules: 'true' | |
- name: Check if special branches exist | |
id: branch-check | |
run: | | |
if [[ $(git ls-remote --heads origin rc) ]]; then | |
echo "rc_branch_exists=1" >> $GITHUB_OUTPUT | |
else | |
echo "rc_branch_exists=0" >> $GITHUB_OUTPUT | |
fi | |
if [[ $(git ls-remote --heads origin hotfix-rc) ]]; then | |
echo "hotfix_branch_exists=1" >> $GITHUB_OUTPUT | |
else | |
echo "hotfix_branch_exists=0" >> $GITHUB_OUTPUT | |
fi | |
f-droid: | |
name: F-Droid Build | |
runs-on: windows-2022 | |
env: | |
android_folder_path: src\App\Platforms\Android | |
android_folder_path_bash: src/App/Platforms/Android | |
android_manifest_path: src/App/Platforms/Android/AndroidManifest.xml | |
permissions: | |
checks: write | |
steps: | |
- name: Setup NuGet | |
uses: nuget/setup-nuget@a21f25cd3998bf370fde17e3f1b4c12c175172f9 # v2.0.0 | |
with: | |
nuget-version: 6.4.0 | |
- name: Set up .NET | |
uses: actions/setup-dotnet@6bd8b7f7774af54e05809fcc5431931b3eb1ddee # v4.0.1 | |
with: | |
dotnet-version: '8.0.x' | |
- name: Set up MSBuild | |
uses: microsoft/setup-msbuild@6fb02220983dee41ce7ae257b6f4d8f9bf5ed4ce # v2.0.0 | |
- name: Setup Windows builder | |
run: choco install checksum --no-progress | |
- name: Setup Java 11 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'microsoft' | |
java-version: '11' | |
- name: Print environment | |
run: | | |
nuget help | grep Version | |
msbuild -version | |
dotnet --info | |
echo "GitHub ref: $GITHUB_REF" | |
echo "GitHub event: $GITHUB_EVENT" | |
- name: Checkout repo | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
- name: Decrypt secrets | |
env: | |
DECRYPT_FILE_PASSWORD: ${{ secrets.DECRYPT_FILE_PASSWORD }} | |
run: | | |
mkdir -p ~/secrets | |
gpg --quiet --batch --yes --decrypt --passphrase="$DECRYPT_FILE_PASSWORD" \ | |
--output ${{ env.android_folder_path_bash }}/app_fdroid-keystore.jks ./.github/secrets/app_fdroid-keystore.jks.gpg | |
shell: bash | |
- name: Increment version | |
run: | | |
BUILD_NUMBER=$((12000 + $GITHUB_RUN_NUMBER)) | |
echo "##### Setting F-Droid Version Code to $BUILD_NUMBER" | tee -a $GITHUB_STEP_SUMMARY | |
sed -i "s/android:versionCode=\"1\"/android:versionCode=\"$BUILD_NUMBER\"/" \ | |
./${{ env.android_manifest_path }} | |
shell: bash | |
- name: Clean for F-Droid | |
run: | | |
$directoryBuildProps = $($env:GITHUB_WORKSPACE + "/Directory.Build.props"); | |
$androidManifest = $($env:GITHUB_WORKSPACE + "/${{ env.android_manifest_path }}"); | |
Write-Output "##### Back up project files" | |
Copy-Item $androidManifest $($androidManifest + ".original"); | |
Copy-Item $directoryBuildProps $($directoryBuildProps + ".original"); | |
Write-Output "##### Cleanup Android Manifest" | |
$xml=New-Object XML; | |
$xml.Load($androidManifest); | |
$nsAndroid=New-Object System.Xml.XmlNamespaceManager($xml.NameTable); | |
$nsAndroid.AddNamespace("android", "http://schemas.android.com/apk/res/android"); | |
$xml.Save($androidManifest); | |
Write-Output "##### Enabling FDROID constant" | |
(Get-Content $directoryBuildProps).Replace('<!-- <CustomConstants>FDROID</CustomConstants> -->', '<CustomConstants>FDROID</CustomConstants>') | Set-Content $directoryBuildProps | |
- name: Restore packages | |
run: dotnet restore | |
- name: Build & Sign F-Droid | |
env: | |
FDROID_KEYSTORE_PASSWORD: ${{ secrets.FDROID_KEYSTORE_PASSWORD }} | |
FDROID_KEY_PASSWORD: ${{ secrets.FDROID_KEY_PASSWORD }} | |
run: | | |
$projToBuild = "$($env:GITHUB_WORKSPACE)\${{ env.main_app_project_path }}"; | |
$packageName = "com.x8bit.bitwarden"; | |
Write-Output "##### Sign FDroid" | |
$signingFdroidKeyStore = "$($env:GITHUB_WORKSPACE)\${{ env.android_folder_path }}\app_fdroid-keystore.jks" | |
dotnet build $projToBuild -c Release -f ${{ env.target-net-version }}-android ` | |
/p:AndroidKeyStore=true ` | |
/p:AndroidSigningKeyStore=$signingFdroidKeyStore ` | |
/p:AndroidSigningKeyAlias=nibblewarden ` | |
/p:AndroidSigningKeyPass="$($env:FDROID_KEY_PASSWORD)" ` | |
/p:AndroidSigningStorePass="$($env:FDROID_KEYSTORE_PASSWORD)" ` --no-restore | |
Write-Output "##### Copy FDroid apk to project root" | |
$signedApkPath = "$($env:GITHUB_WORKSPACE)\${{ env.main_app_folder_path }}\bin\Release\${{ env.target-net-version }}-android\$($packageName)-Signed.apk"; | |
$signedApkDestPath = "$($env:GITHUB_WORKSPACE)\com.x8bit.bitwarden-fdroid.apk"; | |
Copy-Item $signedApkPath $signedApkDestPath | |
- name: Upload F-Droid .apk artifact | |
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4 | |
with: | |
name: com.x8bit.bitwarden-fdroid.apk | |
path: ./com.x8bit.bitwarden-fdroid.apk | |
if-no-files-found: error | |
- name: Create checksum for F-Droid artifact | |
run: | | |
checksum -f="./com.x8bit.bitwarden-fdroid.apk" ` | |
-t sha256 | Out-File -Encoding ASCII ./bw-fdroid-apk-sha256.txt | |
- name: Upload F-Droid sha file | |
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4 | |
with: | |
name: bw-fdroid-apk-sha256.txt | |
path: ./bw-fdroid-apk-sha256.txt | |
if-no-files-found: error | |
check-failures: | |
name: Check for failures | |
if: always() | |
runs-on: ubuntu-22.04 | |
needs: | |
- cloc | |
- f-droid | |
steps: | |
- name: Check if any job failed | |
if: | | |
(github.ref == 'refs/heads/main') | |
|| (github.ref == 'refs/heads/rc') | |
|| (github.ref == 'refs/heads/hotfix-rc') | |
env: | |
CLOC_STATUS: ${{ needs.cloc.result }} | |
F_DROID_STATUS: ${{ needs.f-droid.result }} | |
run: | | |
if [ "$CLOC_STATUS" = "failure" ]; then | |
exit 1 | |
elif [ "$F_DROID_STATUS" = "failure" ]; then | |
exit 1 | |
fi |