From 11f22c51a744d8205171821cec27c0efbc530e97 Mon Sep 17 00:00:00 2001 From: GevinHasmitha Date: Thu, 24 Aug 2023 11:51:33 +0530 Subject: [PATCH 1/4] Fixed issues in fhirr4 and ci workflows --- .github/workflows/cd-fhirr4.yml | 4 +- .github/workflows/ci.yml | 37 ++++ .github/workflows/fhirr4-build-executor.yml | 184 ++++++++++++++++++++ 3 files changed, 223 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/fhirr4-build-executor.yml diff --git a/.github/workflows/cd-fhirr4.yml b/.github/workflows/cd-fhirr4.yml index b30c2563..30a6d908 100644 --- a/.github/workflows/cd-fhirr4.yml +++ b/.github/workflows/cd-fhirr4.yml @@ -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 }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 319bc71d..64241a1c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,6 +8,7 @@ on: env: R4_PATTERN: '*/*' + FHIRR4_PATTERN: 'fhirr4/*/*' UTILS_PATTERN: 'utils/*/*' GITHUB_WORKFLOWS_DIR: '.github' @@ -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 @@ -77,6 +80,7 @@ jobs: uses: actions/checkout@v3 - name: Ballerina Build + if: ${{ matrix.path != 'fhirr4/ballerina/src/main/resources/fhirservice' }} uses: ballerina-platform/ballerina-action@2201.7.0 with: args: pack @@ -84,6 +88,37 @@ jobs: 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' + + - uses: ballerina-platform/setup-ballerina@v1.1.0 + if: ${{ matrix.path == 'fhirr4/ballerina/src/main/resources/fhirservice' }} + name: Setup latest Ballerina version + with: + version: 2201.7.0 + + - name: Create settings.xml + if: ${{ matrix.path == 'fhirr4/ballerina/src/main/resources/fhirservice' }} + run: echo ' + + + ballerina-language-repo + ${{ github.actor }} + ${{ secrets.PAT_TOKEN }} + + + ' > ~/.m2/settings.xml + + - name: Run maven build + if: ${{ matrix.path == 'fhirr4/ballerina/src/main/resources/fhirservice' }} + run: | + cd fhirr4 + mvn clean install + test: needs: [ setup ] runs-on: ubuntu-latest @@ -99,6 +134,7 @@ jobs: uses: actions/checkout@v3 - name: Ballerina Test + if: ${{ matrix.path != 'fhirr4/ballerina/src/main/resources/fhirservice' }} uses: ballerina-platform/ballerina-action@2201.7.0 with: args: test --code-coverage @@ -107,6 +143,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 diff --git a/.github/workflows/fhirr4-build-executor.yml b/.github/workflows/fhirr4-build-executor.yml new file mode 100644 index 00000000..7a91b8a2 --- /dev/null +++ b/.github/workflows/fhirr4-build-executor.yml @@ -0,0 +1,184 @@ +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' + + - uses: ballerina-platform/setup-ballerina@v1.1.0 + name: Setup latest Ballerina version + with: + version: 2201.7.0 + + - name: Print ballerina version + run: bal version + + - name: Create settings.xml + run: echo ' + + + ballerina-language-repo + ${{ github.actor }} + ${{ secrets.PAT_TOKEN }} + + + ' > ~/.m2/settings.xml + + - name: Run maven build + run: | + cd fhirr4 + mvn clean install + + - name: Push to Staging + if: inputs.bal_central_environment == 'STAGE' + uses: ballerina-platform/ballerina-action@2201.7.0 + with: + args: + push + env: + WORKING_DIR: ${{ inputs.working_dir }} + JAVA_HOME: /usr/lib/jvm/default-jvm + BALLERINA_STAGE_CENTRAL: true + BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_STAGE_ACCESS_TOKEN }} + + - name: Run ballerina build for dev + if: inputs.bal_central_environment == 'DEV' + uses: ballerina-platform/ballerina-action@2201.7.0 + with: + args: + pack + env: + WORKING_DIR: ${{ inputs.working_dir }} + JAVA_HOME: /usr/lib/jvm/default-jvm + BALLERINA_DEV_CENTRAL: true + BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_DEV_ACCESS_TOKEN }} + + - name: Run ballerina build for prod + if: inputs.bal_central_environment == 'PROD' + uses: ballerina-platform/ballerina-action@2201.7.0 + with: + args: + pack + env: + WORKING_DIR: ${{ inputs.working_dir }} + JAVA_HOME: /usr/lib/jvm/default-jvm + + - name: Push to Dev + if: inputs.bal_central_environment == 'DEV' + uses: ballerina-platform/ballerina-action@2201.7.0 + with: + args: + push + env: + WORKING_DIR: ${{ inputs.working_dir }} + 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/ballerina-action@2201.7.0 + with: + args: + push + env: + WORKING_DIR: ${{ inputs.working_dir }} + 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 Ballerina.toml + if: ${{ inputs.bal_central_environment == 'PROD' }} + id: increment_patch_version + run: | + CURRENT_VERSION=$(grep -Po -m 1 '(?<=version = ")[\d.]+' ${{ inputs.working_dir }}/Ballerina.toml) + IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION" + PATCH_VERSION=$((VERSION_PARTS[2] + 1)) + NEW_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.$PATCH_VERSION" + sed -i "0,/version = \"${CURRENT_VERSION}\"/s//version = \"${NEW_VERSION}\"/" ${{ inputs.working_dir }}/Ballerina.toml + echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_OUTPUT + echo "CURRENT_VERSION=${CURRENT_VERSION}" >> $GITHUB_OUTPUT + + - name: Ballerina Build after incrementing version + if: ${{ inputs.bal_central_environment == 'PROD' }} + uses: ballerina-platform/ballerina-action@2201.7.0 + with: + args: + pack + env: + WORKING_DIR: ${{ inputs.working_dir }} + JAVA_HOME: /usr/lib/jvm/default-jvm + + - 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 }}/Ballerina.toml + git add ${{ inputs.working_dir }}/Dependencies.toml + 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" From 95d6a632cfe6f5e04ea61f483e4f2b00a158dee3 Mon Sep 17 00:00:00 2001 From: GevinHasmitha Date: Mon, 28 Aug 2023 14:54:48 +0530 Subject: [PATCH 2/4] Fixed issues in workfows --- .github/workflows/ci.yml | 7 ++-- .github/workflows/fhirr4-build-executor.yml | 46 ++++----------------- 2 files changed, 12 insertions(+), 41 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 64241a1c..4f7eed68 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -95,9 +95,9 @@ jobs: java-version: '11' distribution: 'temurin' - - uses: ballerina-platform/setup-ballerina@v1.1.0 + - name: Setup latest Ballerina version + uses: ballerina-platform/setup-ballerina@v1.1.0 if: ${{ matrix.path == 'fhirr4/ballerina/src/main/resources/fhirservice' }} - name: Setup latest Ballerina version with: version: 2201.7.0 @@ -116,8 +116,7 @@ jobs: - name: Run maven build if: ${{ matrix.path == 'fhirr4/ballerina/src/main/resources/fhirservice' }} run: | - cd fhirr4 - mvn clean install + mvn clean install -f fhirr4 test: needs: [ setup ] diff --git a/.github/workflows/fhirr4-build-executor.yml b/.github/workflows/fhirr4-build-executor.yml index 7a91b8a2..84227b72 100644 --- a/.github/workflows/fhirr4-build-executor.yml +++ b/.github/workflows/fhirr4-build-executor.yml @@ -24,8 +24,8 @@ jobs: java-version: '11' distribution: 'temurin' - - uses: ballerina-platform/setup-ballerina@v1.1.0 - name: Setup latest Ballerina version + - name: Setup latest Ballerina version + uses: ballerina-platform/setup-ballerina@v1.1.0 with: version: 2201.7.0 @@ -45,8 +45,7 @@ jobs: - name: Run maven build run: | - cd fhirr4 - mvn clean install + mvn clean install -f fhirr4 - name: Push to Staging if: inputs.bal_central_environment == 'STAGE' @@ -55,33 +54,11 @@ jobs: args: push env: - WORKING_DIR: ${{ inputs.working_dir }} + 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: Run ballerina build for dev - if: inputs.bal_central_environment == 'DEV' - uses: ballerina-platform/ballerina-action@2201.7.0 - with: - args: - pack - env: - WORKING_DIR: ${{ inputs.working_dir }} - JAVA_HOME: /usr/lib/jvm/default-jvm - BALLERINA_DEV_CENTRAL: true - BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_DEV_ACCESS_TOKEN }} - - - name: Run ballerina build for prod - if: inputs.bal_central_environment == 'PROD' - uses: ballerina-platform/ballerina-action@2201.7.0 - with: - args: - pack - env: - WORKING_DIR: ${{ inputs.working_dir }} - JAVA_HOME: /usr/lib/jvm/default-jvm - - name: Push to Dev if: inputs.bal_central_environment == 'DEV' uses: ballerina-platform/ballerina-action@2201.7.0 @@ -89,7 +66,7 @@ jobs: args: push env: - WORKING_DIR: ${{ inputs.working_dir }} + 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 }} @@ -101,7 +78,7 @@ jobs: args: push env: - WORKING_DIR: ${{ inputs.working_dir }} + WORKING_DIR: /fhirr4/ballerina/target/classes/fhirservice JAVA_HOME: /usr/lib/jvm/default-jvm BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_ACCESS_TOKEN }} @@ -140,15 +117,10 @@ jobs: echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_OUTPUT echo "CURRENT_VERSION=${CURRENT_VERSION}" >> $GITHUB_OUTPUT - - name: Ballerina Build after incrementing version + - name: Maven Build after incrementing version if: ${{ inputs.bal_central_environment == 'PROD' }} - uses: ballerina-platform/ballerina-action@2201.7.0 - with: - args: - pack - env: - WORKING_DIR: ${{ inputs.working_dir }} - JAVA_HOME: /usr/lib/jvm/default-jvm + run: | + mvn clean install -f fhirr4 - name: Commit changes and make a PR if: ${{ inputs.bal_central_environment == 'PROD' }} From 030788b5edbd8f67c6f1989774c56d778a455813 Mon Sep 17 00:00:00 2001 From: GevinHasmitha Date: Thu, 31 Aug 2023 09:37:49 +0530 Subject: [PATCH 3/4] Fixed Issues in updating version in pom --- .github/workflows/fhirr4-build-executor.yml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/fhirr4-build-executor.yml b/.github/workflows/fhirr4-build-executor.yml index 84227b72..ce07ca93 100644 --- a/.github/workflows/fhirr4-build-executor.yml +++ b/.github/workflows/fhirr4-build-executor.yml @@ -105,22 +105,21 @@ jobs: }' \ "https://api.github.com/repos/${{ github.repository }}/releases" - - name: Update version in Ballerina.toml + - 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 }}/Ballerina.toml) + CURRENT_VERSION=$(grep -Po -m 1 '(?<=)[\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" - sed -i "0,/version = \"${CURRENT_VERSION}\"/s//version = \"${NEW_VERSION}\"/" ${{ inputs.working_dir }}/Ballerina.toml echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_OUTPUT echo "CURRENT_VERSION=${CURRENT_VERSION}" >> $GITHUB_OUTPUT - - - name: Maven Build after incrementing version - if: ${{ inputs.bal_central_environment == 'PROD' }} - run: | - mvn clean install -f fhirr4 + #Bump the versions in each pom file in fhirr4 + sed -i "0,/${CURRENT_VERSION}<\/version>/s//${NEW_VERSION}<\/version>/" ${{ inputs.working_dir }}/pom.xml + sed -i "0,/${CURRENT_VERSION}<\/version>/s//${NEW_VERSION}<\/version>/" ${{ inputs.working_dir }}/compiler-plugin/pom.xml + sed -i "0,/${CURRENT_VERSION}<\/version>/s//${NEW_VERSION}<\/version>/" ${{ inputs.working_dir }}/native/pom.xml + sed -i "0,/${CURRENT_VERSION}<\/version>/s//${NEW_VERSION}<\/version>/" ${{ inputs.working_dir }}/ballerina/pom.xml - name: Commit changes and make a PR if: ${{ inputs.bal_central_environment == 'PROD' }} @@ -131,7 +130,10 @@ jobs: # 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 }}/Ballerina.toml + 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 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 }} From 93b26ecd5bc8c590624e7808055038445357f394 Mon Sep 17 00:00:00 2001 From: GevinHasmitha Date: Fri, 1 Sep 2023 11:21:50 +0530 Subject: [PATCH 4/4] Removed Dependancies.toml from sstaging area --- .github/workflows/fhirr4-build-executor.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/fhirr4-build-executor.yml b/.github/workflows/fhirr4-build-executor.yml index ce07ca93..1381329b 100644 --- a/.github/workflows/fhirr4-build-executor.yml +++ b/.github/workflows/fhirr4-build-executor.yml @@ -133,8 +133,7 @@ jobs: 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 + git add ${{ inputs.working_dir }}/native/pom.xml 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 }}