Skip to content

Commit

Permalink
fix(.github/workflows): address race condition on terminal "upload-pr…
Browse files Browse the repository at this point in the history
…-info" job

Signed-off-by: Leonardo Grasso <[email protected]>
  • Loading branch information
leogr authored and poiana committed Jan 17, 2025
1 parent 515d40a commit 02eb75a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 39 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ name: Build Plugins PR

on:
pull_request:
branches: [ main ]
branches: [main]

# Checks if any concurrent jobs under the same pull request or branch are being executed
# NOTE: this will cancel every workflow that is being ran against a PR as group is just the github ref (without the workflow name)
concurrency:
group: ci-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
jobs:
build-plugins:
uses: ./.github/workflows/reusable_build_packages.yaml
with:
Expand All @@ -20,15 +20,15 @@ jobs:

get-changed-plugins:
uses: ./.github/workflows/reusable_get_changed_plugins.yaml

build-rules-tool:
needs: [get-changed-plugins]
if: needs.get-changed-plugins.outputs.changed-plugins != '[]' && needs.get-changed-plugins.outputs.changed-plugins != ''
uses: ./.github/workflows/reusable_build_rules_tool.yaml
with:
output: rules-checker
repository: falcosecurity/rules

validate-plugins:
needs: [build-plugins, get-changed-plugins, build-rules-tool]
if: needs.get-changed-plugins.outputs.changed-plugins != '[]' && needs.get-changed-plugins.outputs.changed-plugins != ''
Expand All @@ -44,7 +44,7 @@ jobs:
plugins-artifact: plugins-x86_64-${{ github.event.number }}.tar.gz
rules-checker: ./rules-checker
arch: x86_64

suggest-rules-version:
needs: [build-plugins, get-changed-plugins, build-rules-tool]
if: needs.get-changed-plugins.outputs.changed-plugins != '[]' && needs.get-changed-plugins.outputs.changed-plugins != ''
Expand All @@ -60,3 +60,8 @@ jobs:
rules-checker: ./rules-checker
arch: x86_64
job-index: ${{ strategy.job-index }}

upload-pr-info:
needs: [suggest-rules-version]
if: needs.get-changed-plugins.outputs.changed-plugins != '[]' && needs.get-changed-plugins.outputs.changed-plugins != ''
uses: ./.github/workflows/reusable_upload_pr_info.yaml
34 changes: 0 additions & 34 deletions .github/workflows/reusable_suggest_rules_version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,37 +120,3 @@ jobs:
name: pr-${{ inputs.job-index }}
path: pr/
retention-days: 1

upload-pr-info:
needs: [check-version]
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Download PR infos
uses: actions/download-artifact@v4
with:
path: tmp-artifacts

- name: Save PR info
run: |
mkdir -p ./pr
echo ${{ github.event.number }} > ./pr/NR
touch ./pr/COMMENT
echo "# Rules files suggestions" >> ./pr/COMMENT
echo "" >> ./pr/COMMENT
files=$(find ./tmp-artifacts/)
for file in $files; do
if [[ $file =~ "COMMENT" ]]; then
cat $file >> ./pr/COMMENT
fi
done
echo Uploading PR info...
cat ./pr/COMMENT
echo ""
- name: Upload PR info as artifact
uses: actions/upload-artifact@v4
with:
name: pr
path: pr/
retention-days: 1
37 changes: 37 additions & 0 deletions .github/workflows/reusable_upload_pr_info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This is a reusable workflow used by the PR CI
on:
workflow_call:

jobs:
upload-pr-info:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Download PR infos
uses: actions/download-artifact@v4
with:
path: tmp-artifacts

- name: Save PR info
run: |
mkdir -p ./pr
echo ${{ github.event.number }} > ./pr/NR
touch ./pr/COMMENT
echo "# Rules files suggestions" >> ./pr/COMMENT
echo "" >> ./pr/COMMENT
files=$(find ./tmp-artifacts/)
for file in $files; do
if [[ $file =~ "COMMENT" ]]; then
cat $file >> ./pr/COMMENT
fi
done
echo Uploading PR info...
cat ./pr/COMMENT
echo ""
- name: Upload PR info as artifact
uses: actions/upload-artifact@v4
with:
name: pr
path: pr/
retention-days: 1

0 comments on commit 02eb75a

Please sign in to comment.