Ecosystem branch check #867
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: Ecosystem branch check | |
on: | |
workflow_dispatch: | |
inputs: | |
branch: | |
type: string | |
required: true | |
concurrency: | |
group: ${{ inputs.branch }} | |
cancel-in-progress: true | |
env: | |
repos: "OpenGeode;OpenGeode-IO;OpenGeode-Geosciences;OpenGeode-GeosciencesIO;OpenGeode-Inspector;Geode-Common_private;Geode-Numerics_private;Geode-Conversion_private;Geode-Background_private;Geode-Simplex_private;Geode-SimplexGeosciences_private;Geode-Hybrid_private;Geode-Viewables_private;Geode-Explicit_private;Geode-Implicit_private;Geode-FEFLOW" | |
jobs: | |
validate-PRs: | |
runs-on: ubuntu-latest | |
outputs: | |
base: ${{ steps.check.outputs.base }} | |
repos: ${{ steps.check.outputs.repos }} | |
steps: | |
- uses: actions/github-script@v7 | |
id: check | |
with: | |
github-token: ${{ secrets.TOKEN }} | |
result-encoding: string | |
script: | | |
const repos = "${{ env.repos }}" | |
const owner = 'Geode-solutions' | |
let result = "" | |
let array_repos = [] | |
for(const repo of repos.split(';')) { | |
console.log(repo) | |
array_repos.push(repo) | |
const prs = await github.rest.pulls.list({ | |
owner, | |
repo, | |
state: 'open' | |
}) | |
const branch_pr = prs.data.find(pr => pr.head.ref == "${{ inputs.branch }}") | |
if (!branch_pr) { | |
continue | |
} | |
console.log(branch_pr) | |
const pull_number = branch_pr.number | |
core.setOutput("base", branch_pr.base.ref) | |
const checks = await github.rest.checks.listForRef({ | |
owner, | |
repo, | |
ref: "${{ inputs.branch }}" | |
}) | |
const check_run = checks.data.check_runs.find(check => check.name == "test / deploy-repository / notify / notify") | |
console.log(check_run) | |
if (!check_run || check_run.status != 'completed' || check_run.conclusion != 'success') { | |
const message = 'PR check not completed for ' + repo | |
core.setFailed(message) | |
result += message + '\n' | |
} | |
const pr = await github.rest.pulls.get({ | |
owner, | |
repo, | |
pull_number | |
}) | |
console.log(pr.data) | |
if (!pr.data.mergeable) { | |
const message = 'PR is not mergeable for ' + repo | |
core.setFailed(message) | |
result += message + '\n' | |
} | |
const reviews = await github.rest.pulls.listReviews({ | |
owner, | |
repo, | |
pull_number | |
}); | |
console.log(reviews.data) | |
let changes_requested = [] | |
let approved = false | |
for (const review of reviews.data) { | |
if (review.state == 'APPROVED') { | |
approved = true | |
changes_requested = changes_requested.filter(r => r != review.user.login) | |
} | |
else if (review.state == 'CHANGES_REQUESTED') { | |
changes_requested.push(review.user.login) | |
} | |
} | |
if (changes_requested.length) { | |
console.log(changes_requested) | |
const message = 'PR request changes for ' + repo | |
core.setFailed(message) | |
result += message + '\n' | |
} | |
if (!approved) { | |
const message = 'PR not approved for ' + repo | |
core.setFailed(message) | |
result += message + '\n' | |
} | |
} | |
core.setOutput("repos", JSON.stringify(array_repos)) | |
return result | |
- name: Post to a Slack channel | |
if: failure() | |
id: slack | |
uses: slackapi/slack-github-action@v1 | |
with: | |
channel-id: C0598GTCLGH | |
slack-message: "${{ inputs.branch }}: PR validation failed\n${{ steps.check.outputs.result }}\n${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} | |
linux: | |
needs: validate-PRs | |
runs-on: ubuntu-latest | |
container: ghcr.io/geode-solutions/ubuntu:master | |
outputs: | |
path: ${{ steps.repos.outputs.path }} | |
steps: | |
- uses: Geode-solutions/actions/get-release@master | |
id: repos | |
with: | |
repository: ${{ env.repos }} | |
file: "-ubuntu-private.tar.gz" | |
token: ${{ secrets.TOKEN }} | |
branch: ${{ inputs.branch }} | |
base: ${{ needs.validate-PRs.outputs.base }} | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: linux | |
path: . | |
linux-test: | |
needs: [validate-PRs, linux] | |
runs-on: ubuntu-latest | |
container: ghcr.io/geode-solutions/ubuntu:master | |
strategy: | |
matrix: | |
repo: ${{ fromJSON(needs.validate-PRs.outputs.repos) }} | |
fail-fast: false | |
steps: | |
- uses: actions/download-artifact@v4 | |
with: | |
name: linux | |
- name: Libraries | |
id: libraries | |
run: | | |
new_path=$(echo "${{ needs.linux.outputs.path }}" | sed 's/\;/\/lib\:/g') | |
echo "LD_LIBRARY_PATH=$new_path" >> $GITHUB_ENV | |
- name: Compile | |
run: | | |
gh auth setup-git | |
gh api https://api.github.com/repos/Geode-solutions/open-license-manager/contents/projects/geode/geode.lic -H "Accept: application/vnd.github.raw" > geode.lic | |
gh repo clone Geode-solutions/${{ matrix.repo }} | |
cd ${{ matrix.repo }} | |
if git ls-remote --exit-code --heads origin ${{ inputs.branch }}; then | |
echo "found branch ${{ inputs.branch }}" | |
git checkout origin/${{ inputs.branch }} | |
else | |
git checkout origin/${{ needs.validate-PRs.outputs.base }} | |
fi | |
mkdir -p build | |
cd build | |
cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH="${{ needs.linux.outputs.path }}" ../tests | |
cmake --build . | |
ctest --output-on-failure --no-tests=error -j 2 -LE unstable | |
env: | |
GEODE_LICENSE_LOCATION: ${{ github.workspace }}/geode.lic | |
GITHUB_TOKEN: ${{ secrets.TOKEN }} | |
shell: bash | |
- name: Post to a Slack channel | |
if: failure() | |
id: slack | |
uses: slackapi/slack-github-action@v1 | |
with: | |
channel-id: C0598GTCLGH | |
slack-message: "${{ inputs.branch }}: C++ merge request failed for ${{ matrix.repo }} on Linux\n${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} | |
windows: | |
needs: validate-PRs | |
runs-on: windows-latest | |
outputs: | |
path: ${{ steps.repos.outputs.path }} | |
steps: | |
- uses: Geode-solutions/actions/get-release@master | |
id: repos | |
with: | |
repository: ${{ env.repos }} | |
file: "-win64-private.zip" | |
token: ${{ secrets.TOKEN }} | |
branch: ${{ inputs.branch }} | |
base: ${{ needs.validate-PRs.outputs.base }} | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: windows | |
path: . | |
windows-test: | |
needs: [validate-PRs, windows] | |
runs-on: windows-latest | |
strategy: | |
matrix: | |
repo: ${{ fromJSON(needs.validate-PRs.outputs.repos) }} | |
fail-fast: false | |
steps: | |
- uses: actions/download-artifact@v4 | |
with: | |
name: windows | |
- name: Libraries | |
id: libraries | |
run: | | |
$old_path = "${{ needs.windows.outputs.path }}" | |
$bin_path = $old_path.replace(";", "\bin;").replace("\","/") + "/bin" | |
echo "bin=$bin_path" >> $env:GITHUB_OUTPUT | |
$share_path = $old_path.replace(";", "\share;").replace("\","/") + "/share" | |
echo "share=$share_path" >> $env:GITHUB_OUTPUT | |
- uses: TheMrMilchmann/setup-msvc-dev@v3 | |
with: | |
arch: x64 | |
- name: Compile & Test | |
run: | | |
gh auth setup-git | |
gh api https://api.github.com/repos/Geode-solutions/open-license-manager/contents/projects/geode/geode.lic -H "Accept: application/vnd.github.raw" > geode.lic | |
gh repo clone Geode-solutions/${{ matrix.repo }} | |
cd ${{ matrix.repo }} | |
if git ls-remote --exit-code --heads origin ${{ inputs.branch }}; then | |
echo "found branch ${{ inputs.branch }}" | |
git checkout origin/${{ inputs.branch }} | |
else | |
git checkout origin/${{ needs.validate-PRs.outputs.base }} | |
fi | |
mkdir -p build | |
cd build | |
cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH="${{ needs.windows.outputs.path }}" ../tests | |
IFS=";" read -a paths <<< "${{ steps.libraries.outputs.bin }}" | |
for path in "${paths[@]}" | |
do | |
if [[ -d $path ]]; then | |
cp $path/* bin | |
fi | |
done | |
mkdir share | |
IFS=";" read -a shares <<< "${{ steps.libraries.outputs.share }}" | |
for share in "${shares[@]}" | |
do | |
if [[ -d $share ]]; then | |
cp -r $share/* share | |
fi | |
done | |
cmake --build . | |
ctest --output-on-failure --no-tests=error -j 2 -LE unstable | |
env: | |
GEODE_LICENSE_LOCATION: ${{ github.workspace }}/geode.lic | |
GITHUB_TOKEN: ${{ secrets.TOKEN }} | |
shell: bash | |
- name: Post to a Slack channel | |
if: failure() | |
id: slack | |
uses: slackapi/slack-github-action@v1 | |
with: | |
channel-id: C0598GTCLGH | |
slack-message: "${{ inputs.branch }}: C++ merge request failed for ${{ matrix.repo }} on Windows\n${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} | |
merge-PRs: | |
needs: [linux-test, windows-test] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.TOKEN }} | |
script: | | |
const repos = "${{ env.repos }}" | |
const owner = 'Geode-solutions' | |
for(const repo of repos.split(';')) { | |
console.log(repo) | |
const prs = await github.rest.pulls.list({ | |
owner, | |
repo, | |
state: 'open' | |
}) | |
const branch_pr = prs.data.find(pr => pr.head.ref == "${{ inputs.branch }}") | |
if (!branch_pr) { | |
continue | |
} | |
console.log(branch_pr) | |
const pull_number = branch_pr.number | |
await github.rest.pulls.merge({ | |
owner, | |
repo, | |
pull_number | |
}) | |
} | |
deploy: | |
runs-on: ubuntu-latest | |
needs: [merge-PRs, validate-PRs] | |
steps: | |
- uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.TOKEN }} | |
script: | | |
github.rest.actions.createWorkflowDispatch({ | |
owner: 'Geode-solutions', | |
repo: 'Versions', | |
workflow_id: 'deploy.yml', | |
ref: 'master', | |
inputs: { branch: '${{ needs.validate-PRs.outputs.base }}' } | |
}) | |
- name: Post to a Slack channel | |
id: slack | |
uses: slackapi/slack-github-action@v1 | |
with: | |
channel-id: C0598GTCLGH | |
slack-message: "Merge request for ${{ inputs.branch }} complete :tada:" | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} |