[StepSecurity] Apply security best practices #1
This file contains hidden or 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: Check Compatibility | |
| on: | |
| pull_request_target | |
| jobs: | |
| check-compatibility: | |
| if: github.repository == 'opensearch-project/OpenSearch' | |
| permissions: | |
| contents: read | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Harden the runner (Audit all outbound calls) | |
| uses: step-security/harden-runner@fa2e9d605c4eeb9fcad4c99c224cee0c6c7f3594 # v2.16.0 | |
| with: | |
| egress-policy: audit | |
| - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 | |
| with: | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| - name: Increase swapfile | |
| run: | | |
| sudo swapoff -a | |
| sudo fallocate -l 10G /swapfile | |
| sudo chmod 600 /swapfile | |
| sudo mkswap /swapfile | |
| sudo swapon /swapfile | |
| sudo swapon --show | |
| - name: Run compatibility task | |
| run: ./gradlew checkCompatibility -i | tee $HOME/gradlew-check.out | |
| - name: Get results | |
| run: | | |
| echo '## Compatibility status:' > "${{ github.workspace }}/results.txt" | |
| echo "Checks if related components are compatible with change $(git rev-parse --short HEAD)" >> "${{ github.workspace }}/results.txt" | |
| echo "### Incompatible components" >> "${{ github.workspace }}/results.txt" && grep -e 'Incompatible component' $HOME/gradlew-check.out | sed -e 's/Incompatible component: \[\(.*\)\]/- \1/' >> "${{ github.workspace }}/results.txt" | |
| echo "### Skipped components" >> "${{ github.workspace }}/results.txt" && grep -e 'Skipped component' $HOME/gradlew-check.out | sed -e 's/Skipped component: \[\(.*\)\]/- \1/' >> "${{ github.workspace }}/results.txt" | |
| echo "### Compatible components" >> "${{ github.workspace }}/results.txt" && grep -e 'Compatible component' $HOME/gradlew-check.out | sed -e 's/Compatible component: \[\(.*\)\]/- \1/' >> "${{ github.workspace }}/results.txt" | |
| - name: Upload results | |
| uses: actions/upload-artifact@ff15f0306b3f739f7b6fd43fb5d26cd321bd4de5 # v3.2.1 | |
| with: | |
| name: results.txt | |
| path: ${{ github.workspace }}/results.txt | |
| add-comment: | |
| needs: [check-compatibility] | |
| permissions: | |
| pull-requests: write | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Harden the runner (Audit all outbound calls) | |
| uses: step-security/harden-runner@fa2e9d605c4eeb9fcad4c99c224cee0c6c7f3594 # v2.16.0 | |
| with: | |
| egress-policy: audit | |
| - name: Download results | |
| uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 | |
| with: | |
| name: results.txt | |
| - name: Find Comment | |
| uses: step-security/find-comment@1d7bf2a0c1b6802305aa3cf2e7c0e47568915caf # v4.0.0 | |
| id: fc | |
| with: | |
| issue-number: ${{ github.event.number }} | |
| comment-author: 'github-actions[bot]' | |
| body-includes: 'Compatibility status:' | |
| - name: Add comment on the PR | |
| uses: step-security/create-or-update-comment@a7653e0a4e18093550a274e9c79b7ec6b6dd527e # v5.0.0 | |
| with: | |
| comment-id: ${{ steps.fc.outputs.comment-id }} | |
| issue-number: ${{ github.event.number }} | |
| body-path: results.txt | |
| edit-mode: replace |