Merge Rails LTS branch #1295
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: Merge Rails LTS branch | |
on: | |
schedule: | |
- cron: 0 0-23 * * * | |
jobs: | |
auto-update-fork: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Check changes in makandra/rails/2-3-lts | |
id: check-changes | |
run: | | |
git fetch origin 2-3-lts-for-genius | |
git fetch origin 2-3-lts | |
git remote add makandra https://github.com/makandra/rails.git | |
git fetch makandra 2-3-lts | |
n_new_releases=$(git rev-list --count origin/2-3-lts..makandra/2-3-lts -- railslts-version/lib/railslts-version.rb) | |
if [[ $n_new_releases -eq 0 ]]; then | |
echo "cancel=true" >> $GITHUB_OUTPUT | |
fi | |
- name: Cancel workflow if there is no change | |
if: ${{ steps.check-changes.outputs.cancel == 'true' }} | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const cancelWorkflow = require('./.github/workflows/scripts/cancelWorkflow.js'); | |
return cancelWorkflow({github, context, core}); | |
- name: Update our copy of rails lts branch to the latest release | |
run: | | |
workflow_commit_sha=$(git rev-parse HEAD) | |
last_release_commit_sha=$(git rev-list -n 1 makandra/2-3-lts -- railslts-version/lib/railslts-version.rb) | |
git checkout -b 2-3-lts $last_release_commit_sha | |
git push --set-upstream origin 2-3-lts | |
git checkout $workflow_commit_sha | |
- name: Grab diff | |
id: git-diff | |
run: | | |
pretty_diff=$(git log --pretty=format:"- %s" origin/2-3-lts-for-genius..origin/2-3-lts) | |
echo "pretty_diff<<EOF" >> $GITHUB_OUTPUT | |
echo "$pretty_diff" >> $GITHUB_OUTPUT | |
echo "EOF" >> $GITHUB_OUTPUT | |
- name: Create or grab existing pull request | |
id: pr | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const findOrCreatePr = require('./.github/workflows/scripts/findOrCreatePr.js'); | |
return findOrCreatePr({github, context}); | |
- name: Build slack messages | |
id: messages | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const buildSlackMessages = require('./.github/workflows/scripts/buildSlackMessages.js'); | |
return buildSlackMessages({ | |
prLink: ${{ toJSON(fromJSON(steps.pr.outputs.result).html_url) }}, | |
diff: ${{ toJSON(steps.git-diff.outputs.pretty_diff) }} | |
}); | |
- name: Send slack messages | |
uses: slackapi/[email protected] | |
with: | |
channel-id: ${{ vars.SLACK_CHANNEL_ID }} | |
payload: | | |
{ | |
"text": ${{ toJSON(fromJSON(steps.messages.outputs.result).text) }}, | |
"blocks": [ | |
{ | |
"type": "section", | |
"text": { | |
"type": "mrkdwn", | |
"text": ${{ toJSON(fromJSON(steps.messages.outputs.result).markdown) }} | |
} | |
} | |
] | |
} | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} |