diff --git a/Jenkinsfile b/Jenkinsfile index b86cef2..466412a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -38,6 +38,7 @@ // Initialize lazyConfig for this pipeline lazyConfig( name: 'DummyAnd', + env: [ 'DRYRUN=true' ], ) // Define a method to run Fastlane from the later lazyStages @@ -95,11 +96,8 @@ } def gitLog(bottom = null, top = 'HEAD') { -// Not working without git credentials: def from = bottom ?: 'tags/' + sh(script: "git tag -l | tail -1", returnStdout: true).trim() sh(script: "git --no-pager log ${from}...${top} --pretty=format:'- %s' --reverse", returnStdout: true) -// def date = sh(script: "git --no-pager log --grep=Provide\\ changelogs -n 1 --pretty=format:%cd", returnStdout: true) -// sh(script: "git log --since='${date}' --perl-regexp --author='^(?!.*?bot-ci).*\$' --pretty=format:'- %s' --reverse", returnStdout: true) } @@ -114,22 +112,30 @@ } def gitUpdateChangelogs(versionCode, remote = 'origin', branch = 'master') { + def dryRun = ( env.DRYRUN == 'true' ) ? '--dry-run' : '' def lDir = 'fastlane/metadata/android' sh(""" git status --porcelain ${lDir} | grep -q 'changelogs/${versionCode}\\.txt\$' \ || { echo 'Nothing to update'; exit 0; } +git stash save --quiet --include-untracked changelogs git checkout --quiet ${branch} +git stash pop git add ${lDir}/*/changelogs/${versionCode}.txt git commit --quiet -s -m 'Provide changelogs for this version' ${lDir} -git push ${remote} ${branch} +git push ${dryRun} ${remote} ${branch} """) } def gitTag(version, remote = 'origin' ) { - sh("git tag -a '${version}' -m 'Create new tag for version ${version}' && git push ${remote} ${version}") + def dryRun = ( env.DRYRUN == 'true' ) ? '--dry-run' : '' + sh(""" +git tag -a '${version}' -m 'Create new tag for version ${version}' +git push ${dryRun} ${remote} ${version} +""") } def gitUpdateVersion(versionName, versionCode, remote = 'origin', branch = 'master') { + def dryRun = ( env.DRYRUN == 'true' ) ? '--dry-run' : '' def gradleFilePath = 'app/build.gradle' def gradleFile = readFile(encoding: 'UTF-8', file: gradleFilePath) gName = getVersion('versionName', true) @@ -140,9 +146,11 @@ sh(""" git status --porcelain ${gradleFilePath} | grep -q '${gradleFilePath}\$' \ || { echo 'Nothing to update'; exit 0; } +git stash save --quiet versions git checkout --quiet ${branch} +git stash pop git commit --quiet -s -m 'Update version from ${gName[2]}-${gCode[2]} to ${versionName}-${versionCode}' app/build.gradle -git push ${remote} ${branch} +git push ${dryRun} ${remote} ${branch} """) } @@ -165,29 +173,28 @@ }, post: { archiveArtifacts(artifacts: 'app/build/outputs/apk/**', allowEmptyArchive: false) - //stash(includes: 'app/build/outputs/apk/*', name: 'apk') }, on: 'android', ] } +//if (env.BRANCH_NAME != 'master') return 0 + lazyStage { name = 'release' tasks = [ -// if: { (env.BRANCH_NAME == 'master') }, - pre: { + pre: { unarchive(mapping:['app/build/outputs/apk/' : '.']) sh("ls -lA app/build/outputs/apk") - //unstash('apk') }, - run: { + run: { env -> def currentVersion = [ name: getVersion('versionName') as String, code: getVersion('versionCode') as Integer ] def nextVersion = [ name: currentVersion.name, code: currentVersion.code + 1] echo("currentVersion = ${currentVersion.toString()} / nextVersion = ${nextVersion.toString()}") withGitPassword('bot-ci-dgm', { echo("Git logs since last tag:\n" + gitLog()) prepareChangelogs(currentVersion.code) - fastlane('android', 'release') + if ( env.DRYRUN == 'false' ) fastlane('android', 'alpha') gitUpdateChangelogs(currentVersion.code) gitTag("${currentVersion.name}-${currentVersion.code}") gitUpdateVersion(nextVersion.name, nextVersion.code) @@ -197,7 +204,22 @@ ] } -//lazyStage { -// name = 'publish' -// tasks = [ [ run: [ 'fastlane_beta.sh' ], on: 'android' ] ] -//} +lazyStage { + name = 'acceptance' + tasks = [ + run: { env -> + input('Do we want to promote this release from alpha to beta ?') + if ( env.DRYRUN == 'false' ) fastlane('android', 'beta') + } + ] +} + +lazyStage { env -> + name = 'production' + tasks = [ + run: { + input('Do we want to promote this release from alpha to production ?') + if ( env.DRYRUN == 'false' ) fastlane('android', 'production') + } + ] +} diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 2f5dac3..872ebc9 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -102,7 +102,7 @@ end desc "Submit a new Beta Build to Crashlytics Beta" - lane :beta do + lane :crashlytics do gradle(task: "assembleRelease") crashlytics