diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cfcc22a..64950a9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,58 +1,35 @@ -name: Code Coverage +name: Release Slack Notifications on: pull_request: - branches: - - main - - develop - push: - branches: - - main + types: [opened, synchronize, closed] jobs: - - checks: + slack_notification: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Use Node.js v20.9.0 - uses: actions/setup-node@v3 - with: - node-version: '20.9.0' - - - name: Install dependencies - run: yarn - - - name: Restore Coverage Report (from main) - if: github.ref != 'refs/heads/main' - uses: actions/cache/restore@v4 - with: - path: ./coverage/lcov.info - key: test-coverage-latest-main - - - name: Rename restored coverage report - if: github.ref != 'refs/heads/main' - run: mv ./coverage/lcov.info ./lcov-base.info - - - name: Run test coverage - run: npm run coverage - - - name: Cache Coverage Report (to main) - if: github.ref == 'refs/heads/main' - uses: actions/cache@v3 - with: - path: ./coverage/lcov.info - key: test-coverage-latest-main - - name: Generate Code Coverage report - if: github.ref != 'refs/heads/main' - id: code-coverage - uses: barecheck/code-coverage-action@v1 + - name: Send Slack notification + uses: thunkable/slack-release-notifications@v1.0.5 with: - barecheck-github-app-token: ${{ secrets.BARECHECK_GITHUB_APP_TOKEN }} + slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }} + slack-channel: 'C05PW7HGP36' github-token: ${{ secrets.GITHUB_TOKEN }} - lcov-file: "./coverage/lcov.info" - base-lcov-file: "./lcov-base.info" - minimum-ratio: 50 - send-summary-comment: true - show-annotations: "warning" \ No newline at end of file + initial-message-template: ':traffic_light: <${prUrl}|${prTitle}>' + github-to-slack-map: | + { + "mduchev": "U04K5DCNF18", + "krzysztof-kolakowski": "U03HMV3T2GH", + "opchaves": "U051MKEPJ8Y", + "ommiles": "U02CR4R48JX", + "duckdum": "U0449VAH4BY", + "rminhoto": "U05CT8P804T", + "pecabum": "U0461TZ2A2V", + "pmwthunkable": "U9JSLNYLT", + "JanhaviDahihande": "UJVRSE8D7", + "josmas": "URKH7GXM2", + "TingC": "U6EMD2ZG9", + "andresmechali": "U05QQEPP849", + "Comum": "U04LY9803C1", + "weihuali0509": "U1BCM5ZU4" + } \ No newline at end of file diff --git a/.github/workflows/release-notification-pr-opened.yml b/.github/workflows/release-notification-pr-opened.yml deleted file mode 100644 index 8735158..0000000 --- a/.github/workflows/release-notification-pr-opened.yml +++ /dev/null @@ -1,105 +0,0 @@ -name: Release Notification on PR Opened - -on: - pull_request: - types: [opened, reopened] - -jobs: - notify: - if: startsWith(github.event.pull_request.head.ref, 'release-') - runs-on: ubuntu-latest - steps: - - name: Install jq - run: sudo apt-get install -y jq - - - name: Send initial message to Slack - env: - SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} - SLACK_CHANNEL: 'C05PW7HGP36' # Replace with your Slack channel ID - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - pr_title=$(jq -r .pull_request.title "$GITHUB_EVENT_PATH") - pr_url=$(jq -r .pull_request.html_url "$GITHUB_EVENT_PATH") - branch_name=$(jq -r .pull_request.head.ref "$GITHUB_EVENT_PATH") - target_branch=$(jq -r .pull_request.base.ref "$GITHUB_EVENT_PATH") - initial_message_response=$(curl -s -X POST -H "Authorization: Bearer $SLACK_BOT_TOKEN" -H 'Content-type: application/json' --data "{ - \"channel\": \"$SLACK_CHANNEL\", - \"text\": \"New release pull request created: <$pr_url|$pr_title>\nBranch: $branch_name -> $target_branch\" - }" https://slack.com/api/chat.postMessage) - echo "Initial message response: $initial_message_response" - if echo "$initial_message_response" | jq -e .ok > /dev/null; then - message_ts=$(echo "$initial_message_response" | jq -r .ts) - echo "Message TS: $message_ts" - echo "message_ts=$message_ts" >> $GITHUB_ENV - issue_number=$(jq -r .pull_request.number "$GITHUB_EVENT_PATH") - comment_url="$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/issues/$issue_number/comments" - echo "Comment URL: $comment_url" - comment_response=$(curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" -H 'Content-Type: application/json' --data "{ - \"body\": \"Slack message_ts: $message_ts\" - }" "$comment_url") - echo "Comment response: $comment_response" - else - echo "Failed to retrieve message_ts" - exit 1 - fi - - - name: Fetch and send commit messages to Slack - env: - SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SLACK_CHANNEL: 'C05PW7HGP36' # Replace with your Slack channel ID - run: | - comments_url=$(jq -r .pull_request.comments_url "$GITHUB_EVENT_PATH") - echo "Comments URL: $comments_url" - message_ts=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "$comments_url" | jq -r '.[] | select(.body | startswith("Slack message_ts:")) | .body' | awk '{print $3}') - echo "Retrieved message_ts: $message_ts" - if [ -z "$message_ts" ]; then - echo "Error: No message_ts found in pull request comments." - exit 1 - fi - - declare -A github_to_slack_map=( - ["mduchev"]="@Mihail Duchev" - ["krzysztof-kolakowski"]="@Krzysztof Kołakowski" - ["opchaves"]="@Paulo Chaves" - ["ommiles"]="@O.M. Miles" - ["duckdum"]="@eduardo" - ["rminhoto"]="@Roberto" - ["pecabum"]="@Petar Petrov" - ["pmwthunkable"]="@Paul Medlock-Walton" - ["JanhaviDahihande"]="@janhavi" - ["kkrogmerio"]="@Adrian" - ["TingC"]="@Ting Chou" - ["andresmechali"]="@Andrés Mechali" - ["Comum"]="@Miguel Ribeiro" - ["weihuali0509"]="@Wei Li" - ) - - commits_url=$(jq -r .pull_request.commits_url "$GITHUB_EVENT_PATH") - repo_url=$(jq -r .repository.html_url "$GITHUB_EVENT_PATH") - commits=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "$commits_url") - commit_messages="" - for row in $(echo "${commits}" | jq -r '.[] | @base64'); do - _jq() { - echo ${row} | base64 --decode | jq -r ${1} - } - commit_message=$(_jq '.commit.message') - commit_sha=$(_jq '.sha') - commit_author=$(_jq '.commit.author.name') - commit_url="$repo_url/commit/$commit_sha" - github_user=$(_jq '.author.login') - slack_user=${github_to_slack_map[$github_user]} - if [ -z "$slack_user" ]; then - slack_user=$commit_author - fi - commit_messages="$commit_messages- <$commit_url|$commit_message> by $slack_user\n" - done - if [ -z "$commit_messages" ]; then - commit_messages="No commits found." - fi - echo "Commit messages: $commit_messages" - curl -s -X POST -H "Authorization: Bearer $SLACK_BOT_TOKEN" -H 'Content-type: application/json' --data "{ - \"channel\": \"$SLACK_CHANNEL\", - \"text\": \"Commits in this pull request:\n$commit_messages\", - \"thread_ts\": \"$message_ts\" - }" https://slack.com/api/chat.postMessage \ No newline at end of file diff --git a/.github/workflows/release-notification-pr-synchronize.yml b/.github/workflows/release-notification-pr-synchronize.yml deleted file mode 100644 index 0566d04..0000000 --- a/.github/workflows/release-notification-pr-synchronize.yml +++ /dev/null @@ -1,73 +0,0 @@ -name: Release Notification on PR Updated - -on: - pull_request: - types: [synchronize] - -jobs: - notify: - if: startsWith(github.event.pull_request.head.ref, 'release-') - runs-on: ubuntu-latest - steps: - - name: Install jq - run: sudo apt-get install -y jq - - - name: Fetch message_ts from comments - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - comments_url=$(jq -r .pull_request.comments_url "$GITHUB_EVENT_PATH") - message_ts=$(curl -s -H "Authorization: token $GITHUB_TOKEN" $comments_url | jq -r '.[] | select(.body | startswith("Slack message_ts:")) | .body' | awk '{print $3}') - echo "message_ts=$message_ts" >> $GITHUB_ENV - - - name: Fetch and send commit messages to Slack - env: - SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - message_ts: ${{ env.message_ts }} - SLACK_CHANNEL: 'C05PW7HGP36' # Replace with your Slack channel ID - run: | - declare -A github_to_slack_map=( - ["mduchev"]="@Mihail Duchev" - ["krzysztof-kolakowski"]="@Krzysztof Kołakowski" - ["opchaves"]="@Paulo Chaves" - ["ommiles"]="@O.M. Miles" - ["duckdum"]="@eduardo" - ["rminhoto"]="@Roberto" - ["pecabum"]="@Petar Petrov" - ["pmwthunkable"]="@Paul Medlock-Walton" - ["JanhaviDahihande"]="@janhavi" - ["kkrogmerio"]="@Adrian" - ["TingC"]="@Ting Chou" - ["andresmechali"]="@Andrés Mechali" - ["Comum"]="@Miguel Ribeiro" - ["weihuali0509"]="@Wei Li" - ) - - commits_url=$(jq -r .pull_request.commits_url "$GITHUB_EVENT_PATH") - repo_url=$(jq -r .repository.html_url "$GITHUB_EVENT_PATH") - commits=$(curl -s -H "Authorization: token $GITHUB_TOKEN" $commits_url) - commit_messages="" - for row in $(echo "${commits}" | jq -r '.[] | @base64'); do - _jq() { - echo ${row} | base64 --decode | jq -r ${1} - } - commit_message=$(_jq '.commit.message') - commit_sha=$(_jq '.sha') - commit_author=$(_jq '.commit.author.name') - commit_url="$repo_url/commit/$commit_sha" - github_user=$(_jq '.author.login') - slack_user=${github_to_slack_map[$github_user]} - if [ -z "$slack_user" ]; then - slack_user=$commit_author - fi - commit_messages="$commit_messages- <$commit_url|$commit_message> by $slack_user\n" - done - if [ -z "$commit_messages" ]; then - commit_messages="No commits found." - fi - curl -s -X POST -H "Authorization: Bearer $SLACK_BOT_TOKEN" -H 'Content-type: application/json' --data "{ - \"channel\": \"$SLACK_CHANNEL\", - \"text\": \"New commits added to the release pull request:\n$commit_messages\", - \"thread_ts\": \"$message_ts\" - }" https://slack.com/api/chat.postMessage diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..24474f1 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,28 @@ +name: Comment on Released PRs + +on: + release: + types: [published] + +jobs: + comment-released-prs: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Comment on PRs + uses: apexskier/github-release-commenter@v1 + if: github.event.release.prerelease == false + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + comment-template: | + :tada: This is included in version {release_link} :tada: + + The release is available on: + + * [GitHub releases](https://github.com/duckdum/testcoverage/releases/tag/{release_tag}) + + Cheers! 📦🚀 + label-template: ":rocket: released,release-{release_tag}" + diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml deleted file mode 100644 index bb1853e..0000000 --- a/.github/workflows/sync.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Sync - -on: - push: - branches: - - main -## main test -jobs: - sync-branches: - runs-on: ubuntu-latest - name: Syncing branches - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Create sync pull request - uses: duckdum/sync-branches-gh@v1.8.0 - with: - GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} - FROM_BRANCH: "main" - TO_BRANCH: "develop" - PULL_REQUEST_BODY: "This is an automatic Pull Request to keep develop up to date with main." - CONTENT_COMPARISON: true - REVIEWERS: '["duckdum"]' - \ No newline at end of file diff --git a/README.md b/README.md index d37cd52..6b34ac7 100644 --- a/README.md +++ b/README.md @@ -1 +1,4 @@ -# testcoverage \ No newline at end of file +# testcoverage + +Random text +1 \ No newline at end of file diff --git a/app.js b/app.js index 8455df7..9889bb1 100644 --- a/app.js +++ b/app.js @@ -5,5 +5,8 @@ function sum(a, b) { function subtract(a, b) { return a - b; } - + console.log('c1') + console.log('c2') + console.log('c3') + module.exports = { sum, subtract }; \ No newline at end of file