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

Enabled developer to input PR number for lsp4ij checkout input #1014

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
54 changes: 50 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ on:
required: true
type: boolean
default: false
lsp4ijPrNumber:
description: 'If you checked this, please make sure to enter only the LSP4IJ PR number below'
vaisakhkannan marked this conversation as resolved.
Show resolved Hide resolved
required: true
type: boolean
default: false
refLsp4ij:
description: 'Reference/branch for Lsp4ij checkout'
vaisakhkannan marked this conversation as resolved.
Show resolved Hide resolved
type: string
Expand All @@ -45,7 +50,48 @@ on:
branches: [ main ]

jobs:
fetch_merge_commit_sha_from_lsp4ij_PR:
runs-on: ubuntu-latest
outputs:
pr_details: ${{ steps.extract.outputs.pr_details }}
checkout_name: ${{ steps.extract.outputs.checkout_name }}
env:
API_URL: https://api.github.com/repos/redhat-developer/lsp4ij/pulls
REF_LSP4IJ: ${{ inputs.refLsp4ij }}
LSP4IJ_BRANCH: ${{ inputs.lsp4ijBranch }}
name: Fetch Commit ${{ inputs.refLsp4ij || '' }}
steps:
- name: Extract Merge Commit SHA
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have code in cronJob.yaml to extract the merge commit SHA. Is there any way that we can re-use that code somehow instead of re-doing it here?

Copy link
Contributor Author

@vaisakhkannan vaisakhkannan Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TrevCraw , I tried investigating ways to reuse code from the cronJob.yaml file. We only require a specific portion of the code of the fetch_all_pull_request_shas job, and we do not need the complete job or the other three jobs. During my investigation, I found the following:

GitHub Actions does not support reusing a single job or some portion of a job from one workflow in another. Instead, we can achieve this by creating a new reusable workflow file that includes only the specific job(s) we want to reuse, but we can't create a common code for both the jobs that is, we use different values are being passed in the jobs, such as checkout_name in the fetch_merge_commit_sha_from_lsp4ij_PR job (from build.yaml) and is_empty in the fetch_all_pull_request_shas job. The pr_details variable is common to both jobs but has different values in each case.

If you think to use the code written in the 'Extract Merge Commit SHA' step in an additional workflow file, we should pass the values of ${{ env.REF_LSP4IJ }} and ${{ env.LSP4IJ_BRANCH }} as inputs to the new workflow file. Similarly, we need to get $pr_details and $checkout_name as outputs from the new workflow file, which will result in one additional build beyond the builds listed below.

Screenshot 2024-11-15 at 2 30 36 PM

shell: bash
id: extract
run: |
pr_details="${{ env.REF_LSP4IJ }}"
checkout_name="${{ env.LSP4IJ_BRANCH }}"

if [ "${{ inputs.lsp4ijPrNumber }}" == "true" ]; then
url="${{ env.API_URL }}/${{ env.REF_LSP4IJ }}"
pr_detail=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "$url")
pr_details=$(jq -r '.merge_commit_sha' <<< "$pr_detail" | xargs)
echo "Merge commit SHA of PR ${{ env.REF_LSP4IJ }}: $pr_details"
checkout_name="${{ env.REF_LSP4IJ }}"
if [[ "$pr_details" == "null" ]]; then
echo "::warning file=::The merge commit SHA of the entered PR is null. Please try again later or use a different PR number."
fi
elif [ -z "$pr_details" ]; then
echo "No LSP4IJ checkout found. Using default case."
elif [ -z "$checkout_name" ]; then
echo "Merge Commit SHA/Branch Name/Tag : $pr_details"
checkout_name="${{ env.REF_LSP4IJ }}"
else
echo "Merge Commit SHA/Branch Name/Tag : $pr_details"
fi

# Set output for further steps
echo "pr_details=$pr_details" >> $GITHUB_OUTPUT
echo "checkout_name=$checkout_name" >> $GITHUB_OUTPUT

build:
needs: fetch_merge_commit_sha_from_lsp4ij_PR
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -63,8 +109,8 @@ jobs:
reportName: windows-test-report
env:
USE_LOCAL_PLUGIN: ${{ inputs.useLocalPlugin || false }}
REF_LSP4IJ: ${{ inputs.refLsp4ij }}
LSP4IJ_BRANCH: ${{ inputs.lsp4ijBranch || 'default' }}
REF_LSP4IJ: ${{ needs.fetch_merge_commit_sha_from_lsp4ij_PR.outputs.pr_details }}
LSP4IJ_BRANCH: ${{ needs.fetch_merge_commit_sha_from_lsp4ij_PR.outputs.checkout_name }}
REF_LTI_TAG: ${{ inputs.refLTITag }}
steps:
- name: Configure pagefile
Expand Down Expand Up @@ -108,7 +154,7 @@ jobs:
if: ${{ runner.os == 'Linux' && !failure() }}
uses: actions/[email protected]
with:
name: liberty-tools-intellij-LTI-${{ env.REF_LTI_TAG || 'default' }}-LSP4IJ-${{ env.LSP4IJ_BRANCH }}
name: liberty-tools-intellij-LTI-${{ env.REF_LTI_TAG || 'default' }}-LSP4IJ-${{ env.LSP4IJ_BRANCH || 'default' }}
path: |
./**/*liberty-tools-intellij*.zip
./**/libs/*liberty-tools-intellij*.jar
Expand All @@ -122,6 +168,6 @@ jobs:
if: ${{ failure() && steps.run_tests.conclusion == 'failure' }}
uses: actions/[email protected]
with:
name: ${{ matrix.reportName }}-LTI-${{ env.REF_LTI_TAG || 'default' }}-LSP4IJ-${{ env.LSP4IJ_BRANCH }}
name: ${{ matrix.reportName }}-LTI-${{ env.REF_LTI_TAG || 'default' }}-LSP4IJ-${{ env.LSP4IJ_BRANCH || 'default' }}
path: |
liberty-tools-intellij/build/reports/
8 changes: 8 additions & 0 deletions docs/LSP4IJ-Continuous-Integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ For example, if you want to trigger the Build Workflow from the `main` branch of

<img alt="Example" height="300" src="images/example-manually-trigger.png" width="300" style="display: block; margin: 0 auto;"/>

If you want to check out LSP4IJ based on a PR number, you can check the box labeled `If you checked this, please make sure to enter only the LSP4IJ PR number below` and specify the PR number in the provided text field labeled `Reference/branch for LSP4IJ checkout`. Additionally, you can specify the tag or branch of the `liberty-tools-intellij` repository to be used.
vaisakhkannan marked this conversation as resolved.
Show resolved Hide resolved

> NOTE: Make sure to enable the checkbox labeled `Use lsp4ij locally` as well for this case.

For example, if you want to trigger the Build Workflow from a branch of the LTI repository and build against LSP4IJ PR number `500` while using the `main` branch of LTI, you would configure it as follows:

<img alt="Example" height="300" src="images/Allow-developer-to-input-PR-number.png" width="300" style="display: block; margin: 0 auto;"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the image to show the new text.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the image with the same name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will need to update the other images in the doc where the inputs for running the build.yaml are shown. I think there are two other places in this doc. Check the other doc files as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TrevCraw, I updated the other images in the document and checked the other document files as well, but I couldn't find any images showing the inputs for running the build.yaml.


# How to specify LTI tags or branches in CI-CD builds

The **LTI Tags/Branches** must be specified in two locations within the `cronJob.yaml` file.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading