Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issues in fhirr4 and ci workflows #137

Merged
merged 4 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/cd-fhirr4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ on:

jobs:
build:
uses: ./.github/workflows/build-executor.yml
uses: ./.github/workflows/fhirr4-build-executor.yml
secrets: inherit
with:
working_dir: ./fhirr4/ballerina/src/main/resources/fhirservice
working_dir: ./fhirr4
bal_central_environment: ${{ inputs.bal_central_environment }}
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:

env:
R4_PATTERN: '*/*'
FHIRR4_PATTERN: 'fhirr4/*/*'
UTILS_PATTERN: 'utils/*/*'
GITHUB_WORKFLOWS_DIR: '.github'

Expand Down Expand Up @@ -41,6 +42,8 @@ jobs:
for file in "${CHANGED_FILES_ARRAY[@]}"; do
if [[ $file == $UTILS_PATTERN ]]; then
EXTRACTED_PATH=$(echo "$file" | cut -d '/' -f 1-2)
elif [[ $file == $FHIRR4_PATTERN ]]; then
EXTRACTED_PATH=$(echo "$file" | cut -d '/' -f 1-6)
elif [[ $file == $R4_PATTERN ]]; then
EXTRACTED_PATH=$(echo "$file" | cut -d '/' -f 1)
fi
Expand Down Expand Up @@ -77,13 +80,44 @@ jobs:
uses: actions/checkout@v3

- name: Ballerina Build
if: ${{ matrix.path != 'fhirr4/ballerina/src/main/resources/fhirservice' }}
uses: ballerina-platform/[email protected]
with:
args: pack
env:
WORKING_DIR: ./${{ matrix.path }}
JAVA_HOME: /usr/lib/jvm/default-jvm

- name: Setup Maven
if: ${{ matrix.path == 'fhirr4/ballerina/src/main/resources/fhirservice' }}
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'temurin'

- name: Setup latest Ballerina version
uses: ballerina-platform/[email protected]
if: ${{ matrix.path == 'fhirr4/ballerina/src/main/resources/fhirservice' }}
with:
version: 2201.7.0

- name: Create settings.xml
if: ${{ matrix.path == 'fhirr4/ballerina/src/main/resources/fhirservice' }}
run: echo '<settings>
<servers>
<server>
<id>ballerina-language-repo</id>
<username>${{ github.actor }}</username>
<password>${{ secrets.PAT_TOKEN }}</password>
</server>
</servers>
</settings>' > ~/.m2/settings.xml

- name: Run maven build
if: ${{ matrix.path == 'fhirr4/ballerina/src/main/resources/fhirservice' }}
run: |
mvn clean install -f fhirr4

test:
needs: [ setup ]
runs-on: ubuntu-latest
Expand All @@ -99,6 +133,7 @@ jobs:
uses: actions/checkout@v3

- name: Ballerina Test
if: ${{ matrix.path != 'fhirr4/ballerina/src/main/resources/fhirservice' }}
uses: ballerina-platform/[email protected]
with:
args: test --code-coverage
Expand All @@ -107,6 +142,7 @@ jobs:
JAVA_HOME: /usr/lib/jvm/default-jvm

- name: Read Ballerina Test Results
if: ${{ matrix.path != 'fhirr4/ballerina/src/main/resources/fhirservice' }}
id: test_results
run: |
if [ -f "./${{ matrix.path }}/target/report/test_results.json" ]; then
Expand Down
158 changes: 158 additions & 0 deletions .github/workflows/fhirr4-build-executor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
name: fhirr4-build

on:
workflow_call:
inputs:
working_dir:
required: true
type: string
bal_central_environment:
required: true
type: string

jobs:
release:
runs-on: ubuntu-latest
env:
JAVA_OPTS: -Xmx4G
steps:
- uses: actions/checkout@v3

- name: Setup Java and Maven
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'temurin'

- name: Setup latest Ballerina version
uses: ballerina-platform/[email protected]
with:
version: 2201.7.0

- name: Print ballerina version
run: bal version

- name: Create settings.xml
run: echo '<settings>
<servers>
<server>
<id>ballerina-language-repo</id>
<username>${{ github.actor }}</username>
<password>${{ secrets.PAT_TOKEN }}</password>
</server>
</servers>
</settings>' > ~/.m2/settings.xml

- name: Run maven build
run: |
mvn clean install -f fhirr4

- name: Push to Staging
if: inputs.bal_central_environment == 'STAGE'
uses: ballerina-platform/[email protected]
with:
args:
push
env:
WORKING_DIR: /fhirr4/ballerina/target/classes/fhirservice
JAVA_HOME: /usr/lib/jvm/default-jvm
BALLERINA_STAGE_CENTRAL: true
BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_STAGE_ACCESS_TOKEN }}

- name: Push to Dev
if: inputs.bal_central_environment == 'DEV'
uses: ballerina-platform/[email protected]
with:
args:
push
env:
WORKING_DIR: /fhirr4/ballerina/target/classes/fhirservice
JAVA_HOME: /usr/lib/jvm/default-jvm
BALLERINA_DEV_CENTRAL: true
BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_DEV_ACCESS_TOKEN }}

- name: Push to Prod
if: inputs.bal_central_environment == 'PROD'
uses: ballerina-platform/[email protected]
with:
args:
push
env:
WORKING_DIR: /fhirr4/ballerina/target/classes/fhirservice
JAVA_HOME: /usr/lib/jvm/default-jvm
BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_ACCESS_TOKEN }}

- name: Publish Release
if: inputs.bal_central_environment == 'PROD'
id: publish_release
run: |
# Get Branch Name
BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_OUTPUT
# Release name
RELEASE_NAME=${BRANCH_NAME#release-}
curl \
-s -X POST \
-H "Authorization: Bearer ${{ secrets.BALLERINA_BOT_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
-d '{
"tag_name": "'$RELEASE_NAME'",
"name": "'$RELEASE_NAME'",
"body": "[Automated] Creating tag: '$RELEASE_NAME'.",
"draft": false,
"prerelease": false,
"target_commitish": "'$BRANCH_NAME'"
}' \
"https://api.github.com/repos/${{ github.repository }}/releases"

- name: Update version in the pom files
if: ${{ inputs.bal_central_environment == 'PROD' }}
id: increment_patch_version
run: |
CURRENT_VERSION=$(grep -Po -m 1 '(?<=<version>)[\d.]+' ${{ inputs.working_dir }}/pom.xml)
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
PATCH_VERSION=$((VERSION_PARTS[2] + 1))
NEW_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.$PATCH_VERSION"
echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_OUTPUT
echo "CURRENT_VERSION=${CURRENT_VERSION}" >> $GITHUB_OUTPUT
#Bump the versions in each pom file in fhirr4
sed -i "0,/<version>${CURRENT_VERSION}<\/version>/s//<version>${NEW_VERSION}<\/version>/" ${{ inputs.working_dir }}/pom.xml
sed -i "0,/<version>${CURRENT_VERSION}<\/version>/s//<version>${NEW_VERSION}<\/version>/" ${{ inputs.working_dir }}/compiler-plugin/pom.xml
sed -i "0,/<version>${CURRENT_VERSION}<\/version>/s//<version>${NEW_VERSION}<\/version>/" ${{ inputs.working_dir }}/native/pom.xml
sed -i "0,/<version>${CURRENT_VERSION}<\/version>/s//<version>${NEW_VERSION}<\/version>/" ${{ inputs.working_dir }}/ballerina/pom.xml
GevinHasmitha marked this conversation as resolved.
Show resolved Hide resolved

- name: Commit changes and make a PR
if: ${{ inputs.bal_central_environment == 'PROD' }}
run: |
# Extract the package name from working directory
packageName=$(basename ${{ inputs.working_dir }})

# Commit changes
git config --global user.name ${{ secrets.BALLERINA_BOT_USERNAME }}
git config --global user.email ${{ secrets.BALLERINA_BOT_EMAIL }}
git add ${{ inputs.working_dir }}/pom.xml
git add ${{ inputs.working_dir }}/ballerina/pom.xml
git add ${{ inputs.working_dir }}/compiler-plugin/pom.xml
git add ${{ inputs.working_dir }}/native/pom.xml
git add ${{ inputs.working_dir }}/Dependencies.toml
GevinHasmitha marked this conversation as resolved.
Show resolved Hide resolved
git commit -m "[Release ${packageName} ${{ steps.increment_patch_version.outputs.CURRENT_VERSION }}] Prepare for next dev cycle"
git push origin ${{ steps.publish_release.outputs.BRANCH_NAME }}

# Set the base and head branches
BASE_BRANCH="main"
HEAD_BRANCH="${{ steps.publish_release.outputs.BRANCH_NAME }}"
# Create the pull request using the GitHub REST API
RESPONSE=$(curl -s -X POST \
-H "Authorization: Bearer ${{ secrets.BALLERINA_BOT_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
-d '{
"title": "[Release '"$packageName"' ${{ steps.increment_patch_version.outputs.CURRENT_VERSION }}] Prepare for next dev cycle",
"body": "",
"head": "'"$HEAD_BRANCH"'",
"base": "'"$BASE_BRANCH"'"
}' \
"https://api.github.com/repos/${{ github.repository }}/pulls")
# Extract the pull request URL from the response
PR_URL=$(echo "$RESPONSE" | jq -r '.html_url')

echo "Pull Request created: $PR_URL"