Update build.yaml #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Cron-Job | |
on: | |
schedule: | |
# The job runs every midnight (UTC time) Ref - https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onschedule | |
- cron: '0 0 * * *' | |
workflow_dispatch: | |
push: | |
jobs: | |
fetch_all_pull_request_shass: | |
runs-on: ubuntu-latest | |
outputs: | |
pr_details: ${{ steps.extract.outputs.pr_details }} | |
is_empty: ${{ steps.extract.outputs.is_empty }} | |
env: | |
API_URL: https://api.github.com/repos/redhat-developer/lsp4ij/pulls | |
name: PR Details | |
steps: | |
- name: Extract PR numbers and merge_commit_shas | |
shell: bash | |
id: extract | |
run: | | |
# Fetch PR details from the GitHub API | |
pr_infos=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "${{ env.API_URL }}") | |
# Extract PR numbers and merge_commit_sha values, excluding draft pull requests | |
pr_numbers=$(echo "$pr_infos" | jq -r '.[] | select(.draft == false) | {number: .number, sha: .merge_commit_sha} | @base64') | |
# Array to store PRs that are not drafts and have no merge conflicts | |
declare -a valid_prs=() | |
for pr in $pr_numbers; do | |
# Decode the base64 encoded JSON string | |
pr=$(echo "$pr" | base64 --decode) | |
# Extract PR number | |
number=$(echo "$pr" | jq -r '.number') | |
url="${{ env.API_URL }}/$number" | |
pr_detail=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "$url") | |
mergeable_state=$(jq -r '.mergeable_state' <<< "$pr_detail") | |
if [[ "$mergeable_state" != "dirty" ]]; then | |
pr_number=$(jq -r '.number' <<< "$pr_detail") | |
pr_sha=$(jq -r '.merge_commit_sha' <<< "$pr_detail") | |
pr_link=$(jq -r '.html_url' <<< "$pr_detail") | |
valid_prs+=("{\"number\": \"$pr_number\", \"sha\": \"$pr_sha\", \"link\": \"$pr_link\"}") | |
else | |
echo "::warning file=::PR #$(jq -r '.number' <<< "$pr_detail") has conflicts. See : $(jq -r '.html_url' <<< "$pr_detail")" | |
fi | |
done | |
# Create a JSON string from the array | |
pr_details_array=$(IFS=,; echo "[${valid_prs[*]}]") | |
# Print Pr number and SHA values | |
echo "$pr_details_array" | jq '.[]' | |
# Set the output for further steps | |
echo "pr_details=$pr_details_array" >> $GITHUB_OUTPUT | |
# Check if pr_details_array is empty | |
if [ $(echo "$pr_details_array" | jq length) -eq 0 ]; then | |
echo "::warning file=::There are no open PRs, or all the existing PRs are either drafts or have merge conflicts. Skipping further actions." | |
echo "is_empty=true" >> $GITHUB_OUTPUT | |
else | |
echo "is_empty=false" >> $GITHUB_OUTPUT | |
fi | |
# Run the LTI Tests against each open lsp4ij PRs | |
call-build-workflow-for-each-merge-commit-sha: | |
needs: fetch_all_pull_request_shass | |
if: ${{ needs.fetch_all_pull_request_shass.outputs.is_empty == 'false' }} | |
uses: ./.github/workflows/build.yaml | |
strategy: | |
fail-fast: false | |
matrix: | |
pr_details: ${{ fromJson(needs.fetch_all_pull_request_shass.outputs.pr_details) }} | |
with: | |
useLocalPlugin: true | |
refLsp4ij: ${{ matrix.pr_details.sha }} | |
name: Running PR | |
# Run the LTI Tests against lsp4ij main branch | |
call-build-workflow-for-lsp4ij-main-branch: | |
uses: ./.github/workflows/build.yaml | |
with: | |
useLocalPlugin: true | |
refLsp4ij: main | |
name: Run LTI tests for Lsp4ij Main branch |