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..4f7eed68 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,36 @@ 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' + + - name: Setup latest Ballerina version + uses: ballerina-platform/setup-ballerina@v1.1.0 + 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 ' + + + 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: | + mvn clean install -f fhirr4 + test: needs: [ setup ] runs-on: ubuntu-latest @@ -99,6 +133,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 +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 diff --git a/.github/workflows/fhirr4-build-executor.yml b/.github/workflows/fhirr4-build-executor.yml new file mode 100644 index 00000000..1381329b --- /dev/null +++ b/.github/workflows/fhirr4-build-executor.yml @@ -0,0 +1,157 @@ +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/setup-ballerina@v1.1.0 + 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: | + mvn clean install -f fhirr4 + + - name: Push to Staging + if: inputs.bal_central_environment == 'STAGE' + uses: ballerina-platform/ballerina-action@2201.7.0 + 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/ballerina-action@2201.7.0 + 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/ballerina-action@2201.7.0 + 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 '(?<=)[\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,/${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' }} + 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 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"