fastlane/fastlane

number_of_commits run on GitHub action always returns 1

FeelHippo opened this issue ยท 2 comments

New Issue Checklist

Issue Description

running fastlane run number_of_commits locally returns expected amount of commits from HEAD, while running number_of_commits(all: true) from a GitHub workflow always returns 1

Command executed

number_of_commits(all: true)

Complete output when running fastlane, including the stack trace and command used

fastlane run number_of_commits:

feelhip@Dev-Filippos-MacBook-Pro as-charging-app % fastlane run number_of_commits
[โœ”] ๐Ÿš€ 
[10:42:01]: Get started using a Gemfile for fastlane https://docs.fastlane.tools/getting-started/ios/setup/#use-a-gemfile
[10:42:02]: -------------------------------
[10:42:02]: --- Step: number_of_commits ---
[10:42:02]: -------------------------------
[10:42:02]: $ git rev-parse HEAD
[10:42:02]: โ–ธ f7f63c1cabeb569e7a3bc686f216eac52d4feb00
[10:42:02]: $ git rev-list HEAD --count
[10:42:02]: โ–ธ 109
[10:42:02]: Result: 109

number_of_commits(all: true):

[08:04:38]: ------------------------------
[08:04:38]: --- Step: default_platform ---
[08:04:38]: ------------------------------
[08:04:38]: Driving the lane 'android deploy_updraft' ๐Ÿš€
[08:04:38]: -------------------------------
[08:04:38]: --- Step: number_of_commits ---
[08:04:38]: -------------------------------
[08:04:38]: $ git rev-parse HEAD
[08:04:38]: โ–ธ 1c6884217f56c5951bfb1bc8f27f89656954706b
[08:04:38]: $ git rev-list --all --count
[08:04:38]: โ–ธ 1
 The following is the lane run from GitHub 
desc "Deploy to Updraft"
  lane :deploy_updraft do |options|
    min_build_number = 210006000 # For legacy reason
    build_number = min_build_number + number_of_commits(all: true)
    Dir.chdir("../..") do
      flavor = ENV["FLAVOR"]
      sh "flutter build apk --release --build-number=#{build_number} --flavor %s" % flavor
    end
    updraft
  end

Environment

๐Ÿšซ fastlane environment ๐Ÿšซ

Stack

Key Value
OS 13.3
Ruby 3.3.0
Bundler? false
Git git version 2.39.2 (Apple Git-143)
Installation Source /opt/homebrew/Cellar/fastlane/2.219.0_2/libexec/bin/fastlane
Host macOS 13.3 (22E252)
Ruby Lib Dir /opt/homebrew/Cellar/ruby/3.3.0/lib
OpenSSL Version OpenSSL 3.2.0 23 Nov 2023
Is contained false
Is homebrew true
Is installed via Fabric.app false
Xcode Path /Applications/Xcode.app/Contents/Developer/
Xcode Version 14.3.1
Swift Version 5.8.1

System Locale

Error
No Locale with UTF8 found ๐Ÿšซ

fastlane files:

No Fastfile found

No Appfile found

fastlane gems

Gem Version Update-Status
fastlane 2.219.0 โœ… Up-To-Date

Loaded fastlane plugins:

No plugins Loaded

Loaded gems
Gem Version
error_highlight 0.6.0
did_you_mean 1.6.3
syntax_suggest 2.0.0
public_suffix 5.0.4
addressable 2.8.6
babosa 1.0.4
bundler 2.5.4
colored 1.2
highline 2.0.3
commander 4.6.0
dotenv 2.8.1
emoji_regex 3.2.3
faraday-em_http 1.0.0
faraday-em_synchrony 1.0.0
faraday-excon 1.1.0
faraday-httpclient 1.0.1
faraday-multipart 1.0.4
faraday-net_http 1.0.1
faraday-net_http_persistent 1.2.0
faraday-patron 1.0.0
faraday-rack 1.0.0
faraday-retry 1.0.3
ruby2_keywords 0.0.5
faraday 1.10.3
faraday_middleware 1.2.0
domain_name 0.6.20240107
http-cookie 1.0.5
faraday-cookie_jar 0.0.7
fastimage 2.3.0
gh_inspector 1.1.3
google-apis-androidpublisher_v3 0.54.0
google-apis-playcustomapp_v1 0.13.0
google-cloud-env 1.6.0
google-apis-iamcredentials_v1 0.17.0
google-apis-storage_v1 0.31.0
multi_json 1.15.0
os 1.1.4
googleauth 1.8.1
rake 13.1.0
digest-crc 0.6.5
mini_mime 1.1.5
google-cloud-storage 1.47.0
json 2.7.1
mini_magick 4.12.0
naturally 2.2.1
optparse 0.4.0
plist 3.7.1
rubyzip 2.3.2
security 0.1.3
simctl 1.6.10
terminal-notifier 2.0.0
unicode-display_width 2.5.0
terminal-table 3.0.2
tty-screen 0.8.2
tty-cursor 0.7.1
tty-spinner 0.9.3
word_wrap 1.0.0
rouge 2.0.7
xcpretty 0.3.0
xcpretty-travis-formatter 1.0.1
set 1.1.0
artifactory 3.0.17
aws-eventstream 1.3.0
aws-sigv4 1.8.0
aws-partitions 1.899.0
jmespath 1.6.2
aws-sdk-core 3.191.4
aws-sdk-kms 1.78.0
aws-sdk-s3 1.146.0
base64 0.2.0
nkf 0.2.0
rexml 3.2.6
CFPropertyList 3.0.7
excon 0.110.0
multipart-post 2.4.0
httpclient 2.8.3
jwt 2.8.1
signet 0.19.0
retriable 3.1.2
trailblazer-option 0.1.2
declarative 0.0.20
uber 0.1.0
representable 3.2.0
google-apis-core 0.11.3
google-cloud-errors 1.4.0
google-cloud-core 1.7.0
nanaimo 0.3.0
colored2 3.1.2
claide 1.1.0
atomos 0.1.3
xcodeproj 1.24.0
forwardable 1.3.3
logger 1.6.0
pathname 0.3.0
shellwords 0.2.0
cgi 0.4.1
date 3.3.4
timeout 0.4.1
securerandom 0.3.1
uri 0.13.0
openssl 3.2.0
digest 3.1.1
ipaddr 1.2.6
resolv 0.3.0
time 0.3.0
stringio 3.1.0
open-uri 0.4.1
mutex_m 0.2.0
net-http 0.4.0
net-protocol 0.2.2
ostruct 0.6.0
english 0.8.0
erb 4.0.3
abbrev 0.1.2
tempfile 0.2.1
delegate 0.3.1
fileutils 1.7.2
tmpdir 0.2.0
singleton 0.2.0
open3 0.2.1
prettyprint 0.2.0
pp 0.5.0
find 0.2.0
yaml 0.3.0
psych 5.1.2

generated on: 2024-04-03

this is normal, because there is only one commit on github PRs. This is because the "branch" that is actually being used is the merge between the base branch and the PR branch, not just the PR branch.

if you want to have the real number of commits, you must checkout you base branch (main usually) and your PR branch.

This is how we do it:

    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
          lfs: true

      - name: Checkout base, head branches
        run: |
          git checkout ${{ env.BASE_REF }}
          git checkout ${{ env.HEAD_REF }}
        env:
          BASE_REF: ${{ github.event.pull_request.base.ref }}
          HEAD_REF: ${{ github.head_ref }}

works like a charm, thank you very much for your support