-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathagent_checkout_rebase_action.yml
More file actions
97 lines (83 loc) · 3.68 KB
/
agent_checkout_rebase_action.yml
File metadata and controls
97 lines (83 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# .github/workflows/rebase-express-payments.yml
name: 'Auto Rebase adyenExpressPayments'
# This action will trigger on the creation of new preview release tags
on:
push:
tags:
- '*-preview'
workflow_dispatch:
permissions:
contents: write
jobs:
rebase:
name: Rebase adyenExpressPayments on preview release
runs-on: ubuntu-latest
steps:
# Step 1: Check out the repository's code.
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetches all history for all branches and tags
# Step 2: Set up the Node.js environment to use npm and npx.
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '24' # Or your project's specific Node.js version
cache: 'npm' # Caches npm dependencies for faster runs
# Step 3: Configure Git with a user name and email.
- name: Set up Git
run: |
git config --global user.name 'GitHub Actions'
git config --global user.email 'actions@github.com'
# Step 4: Switch to the adyenExpressPayments branch.
- name: Switch to adyenExpressPayments branch
run: git checkout adyenExpressPayments
# Step 5: Delete all package-lock.json files before the rebase.
- name: Delete package-lock.json files
run: |
find . -name "package-lock.json" -type f -delete
# We must commit this change so the rebase can proceed cleanly.
# The 'if' statement prevents an error if no lock files were found.
if [[ -n $(git status -s) ]]; then
git add .
git commit -m "chore: remove package-lock.json files before rebase and regenerating after"
else
echo "No package-lock.json files found to delete."
fi
# Step 6: Attempt to rebase the branch. If this step fails, we abort the rebase and
# return the branch to its original state
- name: Rebase adyenExpressPayments with develop
run: |
TRIGGERING_TAG="${{ github.ref_name }}"
echo "🔄 Rebasing branch 'adyenExpressPayments' onto tag '$TRIGGERING_TAG'"
if ! git rebase $TRIGGERING_TAG; then
echo "Rebase failed due to conflicts. Aborting."
git rebase --abort
exit 1
fi
# Step 7: Install dependencies after a successful rebase.
# The '--yes' flag for lerna is crucial for non-interactive environments.
- name: Install Dependencies
run: |
if ! npx lerna clean --yes && npm i; then
echo "Generating package-lock files after rebase failed!"
exit 1
fi
# Step 8: Push the changes only if all previous steps were successful.
- name: Push Changes
run: |
git add .
git commit --amend --no-edit
git push origin adyenExpressPayments --force-with-lease
# Step 9: This notification step will run if any of the above steps fail.
- name: Notify on Failure
if: failure()
uses: slackapi/slack-github-action@v1.26.0
with:
# The channel or user ID to send the notification to.
channel-id: '${{ secrets.AGENT_CHECKOUT_ALERT_SLACK_CHANNEL_ID }}'
# A custom message for the Slack notification.
slack-message: "🚨 Automatic rebase of `adyenExpressPayments` failed. Manual intervention is required. Link to failed action: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
env:
# You must store your Slack Bot Token as a secret in your repository settings.
SLACK_BOT_TOKEN: '${{ secrets.AGENT_CHECKOUT_SLACK_BOT_TOKEN }}'