Skip to content

Commit

Permalink
Refactor match version file logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ichengchang committed Jul 23, 2024
1 parent ea891ef commit ead0367
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/compute-app-context.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ env:
DEFAULT_BUMP: patch
MAINLINE: main
VERSION_FILE_PATH: build.gradle
VERSION_LINE_MATCH: "^\\s*version\\s*=\\s*'.*'"
VERSION_LINE_MATCH: "^[ \t]*version[ \t]*=[ \t]*'(.*)'"

jobs:
bumper-job:
Expand Down Expand Up @@ -89,6 +89,16 @@ jobs:
short_sha=${{ needs.bumper-job.outputs.app_short_sha }}
dotenv="${short_sha}.env"
if [[ -n "${{ env.VERSION_FILE_PATH }}" && -n "${{ env.VERSION_LINE_MATCH }}" ]]; then
while IFS= read -r line; do
if [[ $line =~ ${{ env.VERSION_LINE_MATCH }} ]]; then
# Extract the captured group (version line match)
version_line="${BASH_REMATCH[1]}"
echo "Version line: $version_line"
fi
done < ${{ env.VERSION_FILE_PATH }}
fi
cat <<EOF > $dotenv
APP_VERSION=${{ needs.bumper-job.outputs.new_tag }}
APP_BRANCH=${{ needs.bumper-job.outputs.app_branch }}
Expand All @@ -101,7 +111,8 @@ jobs:
REPOSITORY_OWNER=${{ github.repository_owner }}
REPOSITORY_URL=https://github.com/${{ github.repository }}
VERSION_FILE_PATH=${{ env.VERSION_FILE_PATH }}
VERSION_LINE_MATCH=${{ env.VERSION_LINE_MATCH }}
VERSION_LINE_PATTERN=${{ env.VERSION_LINE_MATCH }}
VERSION_LINE_MATCH=${version_line}
EOF
cat $dotenv
Expand Down
6 changes: 0 additions & 6 deletions scripts/ci-hooks/get-app-context.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ function get_app_context_from_artifact {
exit 1
}

function get_version_from_file {
local version_file='./path/to/version_file.txt'
app_version=$(cat $version_file)
echo "app_version=$app_version" >> $GITHUB_OUTPUT
}

mask_token

if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
Expand Down

0 comments on commit ead0367

Please sign in to comment.