Skip to content

Commit 76b1039

Browse files
authored
Carve out a workflow for post-push hooks (ruby#14768)
from check_misc.yml. These steps originally came from git.ruby-lang.org/ruby.git's post-receive hooks. Because it handles a different set of events from what the original check_misc.yml does, it probably allows them to be simpler if they are separated.
1 parent d4a762e commit 76b1039

File tree

2 files changed

+75
-49
lines changed

2 files changed

+75
-49
lines changed

.github/workflows/check_misc.yml

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -20,59 +20,22 @@ jobs:
2020
steps:
2121
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2222
with:
23-
fetch-depth: 100 # for notify-slack-commits
2423
token: ${{ (github.repository == 'ruby/ruby' && !startsWith(github.event_name, 'pull')) && secrets.MATZBOT_AUTO_UPDATE_TOKEN || secrets.GITHUB_TOKEN }}
2524

26-
# Run this step first (even before `make up` in the next step) to make the notification available before any other failure
27-
- name: Notify commit to Slack
28-
run: ruby tool/notify-slack-commits.rb "$GITHUB_OLD_SHA" "$GITHUB_NEW_SHA" refs/heads/master
29-
env:
30-
GITHUB_OLD_SHA: ${{ github.event.before }}
31-
GITHUB_NEW_SHA: ${{ github.event.after }}
32-
SLACK_WEBHOOK_URL_ALERTS: ${{ secrets.SLACK_WEBHOOK_URL_ALERTS }}
33-
SLACK_WEBHOOK_URL_COMMITS: ${{ secrets.SLACK_WEBHOOK_URL_COMMITS }}
34-
SLACK_WEBHOOK_URL_RUBY_JP: ${{ secrets.SLACK_WEBHOOK_URL_RUBY_JP }}
35-
if: ${{ github.repository == 'ruby/ruby' && github.ref == 'refs/heads/master' && github.event_name == 'push' }}
36-
continue-on-error: true # The next auto-style should always run
37-
38-
# Sync git.ruby-lang.org before pushing new commits to avoid duplicated syncs
39-
- name: Sync git.ruby-lang.org
40-
run: |
41-
mkdir -p ~/.ssh
42-
echo "$RUBY_GIT_SYNC_PRIVATE_KEY" > ~/.ssh/id_ed25519
43-
chmod 600 ~/.ssh/id_ed25519
44-
ssh-keyscan -t ed25519 git.ruby-lang.org >> ~/.ssh/known_hosts
45-
ssh -i ~/.ssh/id_ed25519 [email protected] "sudo -u git /home/git/git.ruby-lang.org/bin/update-ruby.sh $GITHUB_REF"
46-
env:
47-
GITHUB_REF: ${{ github.ref }}
48-
RUBY_GIT_SYNC_PRIVATE_KEY: ${{ secrets.RUBY_GIT_SYNC_PRIVATE_KEY }}
49-
if: ${{ github.repository == 'ruby/ruby' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/ruby_')) && github.event_name == 'push' }}
50-
5125
- uses: ./.github/actions/setup/directories
5226
with:
5327
makeup: true
5428
# Skip overwriting MATZBOT_AUTO_UPDATE_TOKEN
5529
checkout: '' # false (ref: https://github.com/actions/runner/issues/2238)
5630

57-
# Run this step early to make sure auto-style commits are pushed
58-
- name: Auto-correct code styles
59-
run: |
60-
set -x
61-
ruby tool/auto-style.rb "$GITHUB_OLD_SHA" "$GITHUB_NEW_SHA" refs/heads/master
62-
env:
63-
GITHUB_OLD_SHA: ${{ github.event.before }}
64-
GITHUB_NEW_SHA: ${{ github.event.after }}
65-
GIT_AUTHOR_NAME: git
66-
GIT_COMMITTER_NAME: git
67-
68-
if: ${{ github.repository == 'ruby/ruby' && github.ref == 'refs/heads/master' && github.event_name == 'push' }}
6931
- name: Check for code styles
7032
run: |
7133
set -x
7234
ruby tool/auto-style.rb "$GITHUB_OLD_SHA" "$GITHUB_NEW_SHA"
7335
env:
7436
GITHUB_OLD_SHA: ${{ github.event.pull_request.base.sha }}
7537
GITHUB_NEW_SHA: ${{ github.event.pull_request.merge_commit_sha }}
38+
# Skip 'push' events because post_push.yml fixes them on push
7639
if: ${{ github.repository == 'ruby/ruby' && startsWith(github.event_name, 'pull') }}
7740

7841
- name: Check if C-sources are US-ASCII
@@ -145,17 +108,6 @@ jobs:
145108
name: ${{ steps.docs.outputs.htmlout }}
146109
if: ${{ steps.docs.outcome == 'success' }}
147110

148-
- name: Push PR notes to GitHub
149-
run: ruby tool/notes-github-pr.rb "$(pwd)/.git" "$GITHUB_OLD_SHA" "$GITHUB_NEW_SHA" refs/heads/master
150-
env:
151-
GITHUB_OLD_SHA: ${{ github.event.before }}
152-
GITHUB_NEW_SHA: ${{ github.event.after }}
153-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
154-
GIT_AUTHOR_NAME: git
155-
GIT_COMMITTER_NAME: git
156-
157-
if: ${{ github.repository == 'ruby/ruby' && github.ref == 'refs/heads/master' && github.event_name == 'push' }}
158-
159111
- uses: ./.github/actions/slack
160112
with:
161113
SLACK_WEBHOOK_URL: ${{ secrets.SIMPLER_ALERTS_URL }} # ruby-lang slack: ruby/simpler-alerts-bot

.github/workflows/post_push.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Post-push
2+
on: push
3+
jobs:
4+
hooks:
5+
name: Post-push hooks
6+
7+
permissions:
8+
contents: write # for Git to git push
9+
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
14+
with:
15+
fetch-depth: 500 # for notify-slack-commits
16+
token: ${{ (github.repository == 'ruby/ruby' && !startsWith(github.event_name, 'pull')) && secrets.MATZBOT_AUTO_UPDATE_TOKEN || secrets.GITHUB_TOKEN }}
17+
18+
# Run this step first (even before `make up` in the next step) to make the notification available before any other failure
19+
- name: Notify commit to Slack
20+
run: ruby tool/notify-slack-commits.rb "$GITHUB_OLD_SHA" "$GITHUB_NEW_SHA" refs/heads/master
21+
env:
22+
GITHUB_OLD_SHA: ${{ github.event.before }}
23+
GITHUB_NEW_SHA: ${{ github.event.after }}
24+
SLACK_WEBHOOK_URL_ALERTS: ${{ secrets.SLACK_WEBHOOK_URL_ALERTS }}
25+
SLACK_WEBHOOK_URL_COMMITS: ${{ secrets.SLACK_WEBHOOK_URL_COMMITS }}
26+
SLACK_WEBHOOK_URL_RUBY_JP: ${{ secrets.SLACK_WEBHOOK_URL_RUBY_JP }}
27+
if: ${{ github.repository == 'ruby/ruby' && github.ref == 'refs/heads/master' && github.event_name == 'push' }}
28+
continue-on-error: true # The next auto-style should always run
29+
30+
- name: Sync git.ruby-lang.org
31+
run: |
32+
mkdir -p ~/.ssh
33+
echo "$RUBY_GIT_SYNC_PRIVATE_KEY" > ~/.ssh/id_ed25519
34+
chmod 600 ~/.ssh/id_ed25519
35+
ssh-keyscan -t ed25519 git.ruby-lang.org >> ~/.ssh/known_hosts
36+
ssh -i ~/.ssh/id_ed25519 [email protected] "sudo -u git /home/git/git.ruby-lang.org/bin/update-ruby.sh $GITHUB_REF"
37+
env:
38+
GITHUB_REF: ${{ github.ref }}
39+
RUBY_GIT_SYNC_PRIVATE_KEY: ${{ secrets.RUBY_GIT_SYNC_PRIVATE_KEY }}
40+
if: ${{ github.repository == 'ruby/ruby' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/ruby_')) && github.event_name == 'push' }}
41+
42+
- uses: ./.github/actions/setup/directories
43+
with:
44+
makeup: true
45+
# Skip overwriting MATZBOT_AUTO_UPDATE_TOKEN
46+
checkout: '' # false (ref: https://github.com/actions/runner/issues/2238)
47+
48+
- name: Auto-correct code styles
49+
run: |
50+
set -x
51+
ruby tool/auto-style.rb "$GITHUB_OLD_SHA" "$GITHUB_NEW_SHA" refs/heads/master
52+
env:
53+
GITHUB_OLD_SHA: ${{ github.event.before }}
54+
GITHUB_NEW_SHA: ${{ github.event.after }}
55+
GIT_AUTHOR_NAME: git
56+
GIT_COMMITTER_NAME: git
57+
58+
if: ${{ github.repository == 'ruby/ruby' && github.ref == 'refs/heads/master' && github.event_name == 'push' }}
59+
60+
- name: Push PR notes to GitHub
61+
run: ruby tool/notes-github-pr.rb "$(pwd)/.git" "$GITHUB_OLD_SHA" "$GITHUB_NEW_SHA" refs/heads/master
62+
env:
63+
GITHUB_OLD_SHA: ${{ github.event.before }}
64+
GITHUB_NEW_SHA: ${{ github.event.after }}
65+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66+
GIT_AUTHOR_NAME: git
67+
GIT_COMMITTER_NAME: git
68+
69+
if: ${{ github.repository == 'ruby/ruby' && github.ref == 'refs/heads/master' && github.event_name == 'push' }}
70+
71+
- uses: ./.github/actions/slack
72+
with:
73+
SLACK_WEBHOOK_URL: ${{ secrets.SIMPLER_ALERTS_URL }} # ruby-lang slack: ruby/simpler-alerts-bot
74+
if: ${{ failure() }}

0 commit comments

Comments
 (0)