Workflow file for this run
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
on: | |
pull_request: | |
types: [closed] | |
branches: | |
- gh-monitor | |
push: | |
branches: | |
- gh-monitor | |
jobs: | |
find-changed-files: | |
if: | | |
(github.event_name == 'pull_request' && github.event.pull_request.merged == true) || | |
(github.event_name == 'push') | |
runs-on: ubuntu-latest | |
outputs: | |
changed_files: ${{ steps.list_changed_files.outputs.changed_files }} | |
authors: ${{ steps.get_authors.outputs.authors }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Determine if PR or Direct Push | |
id: check_event | |
run: | | |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then | |
echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV | |
echo "IS_PR=true" >> $GITHUB_ENV | |
else | |
echo "IS_PR=false" >> $GITHUB_ENV | |
fi | |
- name: Fetch changes | |
run: | | |
git fetch origin main | |
if [[ "${{ env.IS_PR }}" == "true" ]]; then | |
git fetch origin pull/${{ env.PR_NUMBER }}/head:pr-${{ env.PR_NUMBER }} | |
else | |
git fetch origin | |
fi | |
- name: List changed files | |
id: list_changed_files | |
run: | | |
if [[ "${{ env.IS_PR }}" == "true" ]]; then | |
CHANGED_FILES=$(git diff --name-only main...pr-${{ env.PR_NUMBER }}) | |
DIFF=$(git diff main...pr-${{ env.PR_NUMBER }}) | |
else | |
PREVIOUS_COMMIT=$(git rev-parse HEAD^1) | |
CHANGED_FILES=$(git diff --name-only ${PREVIOUS_COMMIT}...${GITHUB_SHA}) | |
DIFF=$(git diff ${PREVIOUS_COMMIT}...${GITHUB_SHA}) | |
fi | |
echo "CHANGED_FILES=$CHANGED_FILES" >> $GITHUB_ENV | |
echo "::set-output name=changed_files::$CHANGED_FILES" | |
echo "$DIFF" > report.txt | |
- name: Get commit authors | |
id: get_authors | |
run: | | |
if [[ "${{ env.IS_PR }}" == "true" ]]; then | |
AUTHORS=$(git log --format='%ae' main...pr-${{ env.PR_NUMBER }} | sort | uniq) | |
else | |
PREVIOUS_COMMIT=$(git rev-parse HEAD^1) | |
AUTHORS=$(git log --format='%ae' ${PREVIOUS_COMMIT}...${GITHUB_SHA} | sort | uniq) | |
fi | |
echo "AUTHORS=$AUTHORS" >> $GITHUB_ENV | |
echo "::set-output name=authors::$AUTHORS" | |
- name: Output changed files and authors | |
run: | | |
echo "Changed files: ${{ env.CHANGED_FILES }}" | |
echo "Authors: ${{ env.AUTHORS }}" | |
- name: Save changed files and authors to a file | |
run: | | |
echo "Changed files: ${{ env.CHANGED_FILES }}" > changed_files.txt | |
echo "Authors: ${{ env.AUTHORS }}" >> changed_files.txt | |
cat report.txt >> changed_files.txt | |
- name: Upload changed files artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: changed-files | |
path: changed_files.txt | |
- name: Upload diff report artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: diff-report | |
path: report.txt | |
notify-update: | |
runs-on: ubuntu-latest | |
needs: [find-changed-files] | |
if: success() | |
steps: | |
- name: Download diff report | |
uses: actions/download-artifact@v2 | |
with: | |
name: diff-report | |
path: . | |
- name: Notify Discord with update | |
run: | | |
DIFF_CONTENT=$(cat report.txt) | |
curl -X POST -H "Content-Type: application/json" \ | |
-d "{\"content\": \"<@762664509813817345> Update on GH. Authors: ${{ needs.find-changed-files.outputs.authors }}. Changed files: ${{ needs.find-changed-files.outputs.changed_files }}. Diff report: \n\`\`\`${DIFF_CONTENT}\`\`\`\"}" \ | |
${{ secrets.GH_MONITOR_WEBHOOK }} |