Skip to content

Commit db484ff

Browse files
authored
[PM-10877] Use new version calculation in CI-main workflow (#970)
1 parent 3544d94 commit db484ff

File tree

2 files changed

+69
-56
lines changed

2 files changed

+69
-56
lines changed

.github/workflows/CI-main.yml

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -12,84 +12,84 @@ on:
1212
build-number:
1313
description: "Version Number Override - e.g. '1021'"
1414
type: number
15-
15+
patch_version:
16+
description: "Patch Version Override - e.g. '999'"
17+
type: string
18+
distribute:
19+
description: "Distribute to TestFlight"
20+
type: boolean
1621
env:
1722
XCODE_VERSION: '15.4'
18-
23+
DISTRIBUTE_TO_TESTFLIGHT: ${{ github.event_name == 'push' || inputs.distribute }}
1924
jobs:
2025
resolve-values:
2126
name: "Resolve values"
22-
runs-on: macos-14
27+
runs-on: ubuntu-latest
2328
outputs:
24-
build_variant: ${{ steps.calculate.outputs.variant }}
25-
build_version: ${{ steps.calculate.outputs.version }}
26-
build_number: ${{ steps.calculate.outputs.build_number }}
27-
xcode_version: ${{ steps.calculate.outputs.xcode_version }}
28-
29+
version_name: ${{ steps.version_info.outputs.version_name }}
30+
version_number: ${{ steps.version_info.outputs.version_number }}
31+
xcode_version: ${{ env.XCODE_VERSION }}
32+
distribute_to_testflight: ${{ env.DISTRIBUTE_TO_TESTFLIGHT }}
2933
steps:
30-
- name: Check out repo
31-
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
32-
with:
33-
fetch-depth: 0
34-
filter: tree:0
35-
36-
- name: Calculate build version and number
37-
id: calculate
34+
- name: Log inputs to job summary
3835
run: |
39-
if [[ ! -z "${{ inputs.build-version }}" ]]; then
40-
echo -e "\nApplying build version override"
41-
next_version=${{ inputs.build-version }}
42-
else
43-
echo -e "\nCalculating next version..."
44-
current_year=$(date +%Y)
45-
current_month=$(date +%-m)
36+
echo "<details><summary>CI-main Workflow Inputs</summary>" >> $GITHUB_STEP_SUMMARY
37+
echo "" >> $GITHUB_STEP_SUMMARY
38+
echo '```json' >> $GITHUB_STEP_SUMMARY
39+
echo '${{ toJson(inputs) }}' >> $GITHUB_STEP_SUMMARY
40+
echo '```' >> $GITHUB_STEP_SUMMARY
41+
echo "</details>" >> $GITHUB_STEP_SUMMARY
4642
47-
latest_tag_version=$(git tag --sort=committerdate --list | tail -1)
48-
latest_version=${latest_tag_version:1} # remove 'v' from tag version
49-
50-
latest_major_version=$(echo $latest_version | cut -d "." -f 1)
51-
latest_minor_version=$(echo $latest_version | cut -d "." -f 2)
52-
latest_patch_version=$(echo $latest_version | cut -d "." -f 3)
53-
54-
echo " Current Year: $current_year"
55-
echo " Current Month: $current_month"
56-
echo " Latest Version: $latest_version"
57-
echo " Latest Major Version: $latest_major_version"
58-
echo " Latest Minor Version: $latest_minor_version"
59-
echo " Latest Patch Version: $latest_patch_version"
43+
- name: Calculate version
44+
if: ${{ inputs.build-number == '' || inputs.build-version == '' }}
45+
uses: bitwarden/ios/.github/actions/dispatch-and-download@main
46+
id: dispatch-version
47+
with:
48+
token: ${{ secrets.GITHUB_TOKEN }}
49+
repo: ios
50+
owner: bitwarden
51+
workflow: _version.yml
52+
workflow_inputs: '{"base_version_number": "1000", "version_name": "${{ inputs.build-version }}", "version_number": "${{ inputs.build-number }}", "patch_version": "${{ inputs.patch_version }}"}'
6053

61-
if [[ "$current_year" == "$latest_major_version" && "$current_month" == "$latest_minor_version" ]]; then
62-
next_version="${latest_major_version}.${latest_minor_version}.$(($latest_patch_version + 1))"
63-
else
64-
next_version="${current_year}.${current_month}.0"
65-
fi
66-
fi
54+
- name: Read version info
55+
id: version_info
56+
run: |
57+
# test if dispatch-version was skipped. In that case, creates the same .json file expected by the Upload artifact step
58+
if [ ! -f version-info/version_info.json ]; then
59+
echo "::warning::version-version.json not found, was the previous step skipped? Creating a new file"
60+
json='{
61+
"version_number": "${{ inputs.build-number }}",
62+
"version_name": "${{ inputs.build-version }}"
63+
}'
6764
68-
if [[ ! -z "${{ inputs.build-number }}" ]]; then
69-
echo -e "\nApplying build number override"
70-
next_number=${{ inputs.build-number }}
65+
# file will be used by the upload step
66+
mkdir version-info
67+
echo "$json" > version-info/version_info.json
7168
else
72-
echo -e "\nCalculating build number..."
73-
next_number=$(($GITHUB_RUN_NUMBER + 1000))
69+
echo "::notice::version-version.json found!"
7470
fi
7571
76-
echo -e "\n"
77-
echo "**Version**: $next_version" | tee -a $GITHUB_STEP_SUMMARY
78-
echo "**Build Number**: $next_number" | tee -a $GITHUB_STEP_SUMMARY
79-
echo "version=$next_version" >> $GITHUB_OUTPUT
80-
echo "build_number=$next_number" >> $GITHUB_OUTPUT
81-
echo "xcode_version=$XCODE_VERSION" >> $GITHUB_OUTPUT
72+
content=$(cat version-info/version_info.json)
73+
echo "version_name=$(echo $content | jq -r .version_name)" >> $GITHUB_OUTPUT
74+
echo "version_number=$(echo $content | jq -r .version_number)" >> $GITHUB_OUTPUT
75+
- name: Upload version info artifact
76+
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
77+
with:
78+
name: version-info
79+
path: version-info/version_info.json
8280

8381
build:
8482
name: Build
8583
needs: resolve-values
86-
uses: ./.github/workflows/build.yml
84+
uses: bitwarden/ios/.github/workflows/build.yml@main
8785
strategy:
8886
matrix:
8987
variant: [Beta, Production]
9088
with:
9189
build-variant: ${{ matrix.variant }}
92-
build-version: ${{ needs.resolve-values.outputs.build_version }}
93-
build-number: ${{ needs.resolve-values.outputs.build_number }}
90+
build-version: ${{ needs.resolve-values.outputs.version_name }}
91+
build-number: ${{ needs.resolve-values.outputs.version_number }}
9492
xcode-version: ${{ needs.resolve-values.outputs.xcode_version }}
93+
distribute: ${{ fromJSON(needs.resolve-values.outputs.distribute_to_testflight) }}
94+
upload_version_info: false
9595
secrets: inherit

.github/workflows/build.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ on:
3131
patch_version:
3232
description: "Patch Version Override - e.g. '999'"
3333
type: string
34+
distribute:
35+
description: "Distribute to TestFlight"
36+
type: boolean
37+
default: true
3438
workflow_call:
3539
inputs:
3640
build-variant:
@@ -55,6 +59,12 @@ on:
5559
patch_version:
5660
description: "Patch Version Override - e.g. '999'"
5761
type: string
62+
distribute:
63+
description: "Distribute to TestFlight"
64+
type: boolean
65+
upload_version_info:
66+
description: "Upload version-info file - When false, caller may be handling it already"
67+
type: boolean
5868
env:
5969
BUILD_VARIANT: ${{ inputs.build-variant || 'Beta' }}
6070
XCODE_VERSION: ${{ inputs.xcode-version || '15.4' }}
@@ -84,6 +94,7 @@ jobs:
8494
filter: tree:0
8595

8696
- name: Calculate version
97+
if: ${{ inputs.build-number == '' || inputs.build-version == '' }}
8798
uses: bitwarden/ios/.github/actions/dispatch-and-download@main
8899
id: dispatch-version
89100
with:
@@ -116,6 +127,7 @@ jobs:
116127
echo "version_name=$(echo $content | jq -r .version_name)" >> $GITHUB_OUTPUT
117128
echo "version_number=$(echo $content | jq -r .version_number)" >> $GITHUB_OUTPUT
118129
- name: Upload version info artifact
130+
if: ${{ inputs.upload_version_info }}
119131
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
120132
with:
121133
name: version-info
@@ -349,6 +361,7 @@ jobs:
349361
--apiIssuer "${{ secrets.APP_STORE_CONNECT_TEAM_ISSUER }}"
350362
351363
- name: Upload app to TestFlight with Fastlane
364+
if: ${{ inputs.distribute }}
352365
run: |
353366
CHANGELOG="$(git show -s --format=%s)
354367
$GITHUB_REPOSITORY/$GITHUB_REF_NAME @ $GITHUB_SHA

0 commit comments

Comments
 (0)