Skip to content

Commit

Permalink
Refactor to ideal step architecture (#90)
Browse files Browse the repository at this point in the history
* Broke up functionality in main.go into separate methods.

* Further refactoring

* Finished refactoring.

* Moved methods around.

* Adding comments to satisfy linter.

* Updating comments to satisfy linter.

* Adding comments to satisfy linter

* Handled error returned from Run function

* Split functionality into different files per PR feedback

* Remove duplicate error message

* Update short version.

* fix typo in version setting script

* Trying something

* set build version to 1.0.1

* Update config.go

Co-authored-by: Olivér Falvai <[email protected]>

* Update receiver name to match Go coding conventions

* Fix linter error

* Fix build errors

* Conform to new error messaging

* Added error formatting

* test commit

* Revert "test commit"

This reverts commit b11904a.

* Fix issue with version numbers not incrementing properly when multiple uploads are made to appstore connect in the same workflow

* Migrate to v2 for utils and steputils

* Migrate to v2 for utils and steputils

* Reverted some conversions to v2

* Added back missing function call

* Updating build number code one more time

* Upgrade to go-utils v2 for pathutil and retry

* Set go version to 1.17 to match oldest version on stacks

* Added a few unit tests

* Skip cache workdlow and make build fail on fastlane upload to check build log output.

* Fix linter error

* Fix unit test

* Fix unit test

* Switched to using check step for testing. Updated error messaging.

* Fix linter errors

* Fixed build error

* Restore cache workflow

* Remove commented code

* Use logger instance instead of fmt

* Moved gemVersions to Config, refactored InstallDependencies to remove config input

* Remove default values from initializer

* Add Inputs struct to Config

* Added summaries for inputs in step.yml to satisfy linter warnings

* Fix compile errors in unit tests

* Fix input unmarshalling

* Utilize new command error format

* Added RunOpts, moved caching to Run phase, fixed creation of multiple environment repositories

* Utilize new command error format, and migrate to using logger in step

* Used short variable declaration to keep the scope of errors as short as possible, moved caching functions to step struct

* Return error for inability to parse gemfile, fix logging level for non errors

* Converted errors to warnings, handled with new error messaging, fixed typo in step.yml

* Updated fastlane errors to match new error format

* Updated name of error variable for clarity

* Updated command error format to latest

* Reduce some duplicate code around error handling

* rename formattedCommandErrorMessage and make it return an error

* Make the step print the inputs instead of the processed config

* Update fastlane failure warning log message

* Channel stderr of the fastlane env cmd to the fastlane_env.log file

* Update logs

* Update logs

* Update Fastlane command error message

Co-authored-by: Olivér Falvai <[email protected]>
Co-authored-by: Krisztián Gödrei <[email protected]>
  • Loading branch information
3 people authored Nov 21, 2022
1 parent efd844d commit 85117c0
Show file tree
Hide file tree
Showing 143 changed files with 90,080 additions and 838 deletions.
51 changes: 22 additions & 29 deletions bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
workflows:
ci:
before_run:
- audit-this-step
- go-tests
after_run:
- test

go-tests:
steps:
- go-list: {}
- golint: {}
- errcheck: {}
- go-test: {}
- git::https://github.com/bitrise-steplib/steps-check.git: { }

test:
before_run:
Expand All @@ -23,14 +19,14 @@ workflows:

auth-all:
before_run:
- auth-test-api-key-connection
- auth-test-apple-id-connection
- auth-test-api-key-input
- auth-test-apple-id-connection-globally-set-app-specific-password
- auth-test-api-key-connection
- auth-test-apple-id-connection
- auth-test-api-key-input
- auth-test-apple-id-connection-globally-set-app-specific-password

cache:
cache:
envs:
- SAMPLE_APP_URL: "https://github.com/bitrise-io/sample-apps-flutter-veggieseasons.git"
- SAMPLE_APP_URL: https://github.com/bitrise-io/sample-apps-flutter-veggieseasons.git
- BRANCH: master
- XCODE_SCHEME: Runner
steps:
Expand All @@ -47,7 +43,7 @@ workflows:
inputs:
- repository_url: $SAMPLE_APP_URL
- branch: $BRANCH
- clone_into_dir: "."
- clone_into_dir: .
- path::./:
title: Smoke test to check if Fastlane receives session-based Apple Developer connection
inputs:
Expand Down Expand Up @@ -112,7 +108,7 @@ workflows:
- verbose_log: "yes"
- connection: apple_id
- app_password: ""

auth-test-api-key-connection:
before_run:
- _auth_prepare
Expand Down Expand Up @@ -153,7 +149,7 @@ workflows:

_auth_prepare:
envs:
- SAMPLE_APP_URL: "https://github.com/bitrise-samples/sample-apps-fastlane-test.git"
- SAMPLE_APP_URL: https://github.com/bitrise-samples/sample-apps-fastlane-test.git
- BRANCH: master
- INFO_PLIST_PATH: ./sample-apps-fastlane-test/Info.plist
steps:
Expand All @@ -174,18 +170,25 @@ workflows:
inputs:
- repository_url: $SAMPLE_APP_URL
- branch: $BRANCH
- clone_into_dir: "."
- certificate-and-profile-installer: {}
- clone_into_dir: .
- certificate-and-profile-installer: { }
- script:
inputs:
- content: |-
#!/usr/bin/env bash
CURRENT_BUILD_NUMBER=${BITRISE_BUILD_NUMBER}
if [[ -z "$E2E_ORIG_BUILD_NUM" ]]; then
envman add --key E2E_ORIG_BUILD_NUM --value "$CURRENT_BUILD_NUMBER"
else
CURRENT_BUILD_NUMBER="$E2E_ORIG_BUILD_NUM"
fi
BITRISE_BUILD_NUMBER=$((($(gdate +%Y%m%d%H%M%S)-20000000000000)*10000))
if [[ -z "${BITRISE_BUILD_NUMBER}" ]]; then
echo "error: failed to calculated build number"
exit 1
fi
if [[ -n "${CURRENT_BUILD_NUMBER}" ]]; then
BITRISE_BUILD_NUMBER=$((${BITRISE_BUILD_NUMBER}+${CURRENT_BUILD_NUMBER}))
fi
Expand All @@ -198,14 +201,4 @@ workflows:
- build_version: $BITRISE_BUILD_NUMBER
- plist_path: $INFO_PLIST_PATH
- build_version_offset: $BITRISE_BUILD_VERSION_OFFSET


audit-this-step:
title: Audit the step
steps:
- script:
inputs:
- content: |-
#!/bin/bash
set -ex
stepman audit --step-yml ./step.yml
- build_short_version_string: 1.0.2
54 changes: 44 additions & 10 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"fmt"
"path/filepath"
"reflect"
"runtime"
"strings"

"github.com/bitrise-io/bitrise-init/scanners/android"
Expand All @@ -16,13 +18,45 @@ import (

type depsFunc func(dir string) ([]string, []string, error)

var depsFuncs = []depsFunc{
cocoapodsDeps,
carthageDeps,
androidDeps,
func (f FastlaneRunner) cacheDeps(opts RunOpts) {
if opts.EnableCache {
f.logger.Println()
f.logger.Infof("Collecting cache")

var depsFuncs = []depsFunc{
f.cocoapodsDeps,
f.carthageDeps,
f.androidDeps,
}

c := cache.New()
for _, depFunc := range depsFuncs {
includes, excludes, err := depFunc(opts.WorkDir)
f.logger.Debugf("%s found include path:\n%s\nexclude paths:\n%s", f.functionName(depFunc), strings.Join(includes, "\n"), strings.Join(excludes, "\n"))
if err != nil {
f.logger.Warnf("failed to collect dependencies: %s", err.Error())
continue
}

for _, item := range includes {
c.IncludePath(item)
}

for _, item := range excludes {
c.ExcludePath(item)
}
}
if err := c.Commit(); err != nil {
f.logger.Warnf("failed to commit paths to cache: %s", err)
}
}
}

func (f FastlaneRunner) functionName(i interface{}) string {
return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
}

func iosDeps(dir string, buildDirName, lockFileName string) ([]string, []string, error) {
func (f FastlaneRunner) iosDeps(dir string, buildDirName, lockFileName string) ([]string, []string, error) {
files, err := pathutil.ListPathInDirSortedByComponents(dir, false)
if err != nil {
return nil, nil, fmt.Errorf("failed to search for files in (%s), error: %s", dir, err)
Expand Down Expand Up @@ -62,15 +96,15 @@ func iosDeps(dir string, buildDirName, lockFileName string) ([]string, []string,
return include, nil, nil
}

func cocoapodsDeps(dir string) ([]string, []string, error) {
return iosDeps(dir, "Pods", "Podfile.lock")
func (f FastlaneRunner) cocoapodsDeps(dir string) ([]string, []string, error) {
return f.iosDeps(dir, "Pods", "Podfile.lock")
}

func carthageDeps(dir string) ([]string, []string, error) {
return iosDeps(dir, "Carthage", "Cartfile.resolved")
func (f FastlaneRunner) carthageDeps(dir string) ([]string, []string, error) {
return f.iosDeps(dir, "Carthage", "Cartfile.resolved")
}

func androidDeps(dir string) ([]string, []string, error) {
func (f FastlaneRunner) androidDeps(dir string) ([]string, []string, error) {
scanner := android.NewScanner()
detected, err := scanner.DetectPlatform(dir)
if err != nil {
Expand Down
Loading

0 comments on commit 85117c0

Please sign in to comment.