Skip to content

Commit 0d93d2f

Browse files
authored
chore: upgrade github actions to latest versions (#42)
1 parent 9204a58 commit 0d93d2f

8 files changed

+279
-68
lines changed
+19-9
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
1-
name: Create new hotfix branch
1+
name: Create a new hotfix branch
22

33
on:
44
workflow_dispatch:
55
inputs:
6-
hotfix_name:
7-
description: Hotfix branch name
6+
hotfix_branch_name:
7+
description: Hotfix branch name ('hotfix/' is automatically prepended)
88
required: true
99

1010
jobs:
1111
create-branch:
12-
name: Create new branch
12+
name: Create a new hotfix branch
1313
runs-on: ubuntu-latest
1414
if: github.ref == 'refs/heads/main'
1515
steps:
16-
- name: Create branch
17-
uses: peterjgrainger/[email protected]
18-
env:
19-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16+
- name: Checkout source code
17+
uses: actions/checkout@v4
2018
with:
21-
branch: 'hotfix/${{ github.event.inputs.hotfix_name }}'
19+
fetch-depth: 0
20+
21+
# In order to make a commit, we need to initialize a user.
22+
# You may choose to write something less generic here if you want, it doesn't matter functionality wise.
23+
- name: Initialize mandatory git config
24+
run: |
25+
git config user.name "GitHub actions"
26+
git config user.email [email protected]
27+
28+
- name: Create hotfix branch
29+
run: |
30+
chmod +x scripts/create-hotfix-branch.sh
31+
./scripts/create-hotfix-branch.sh "${{ github.event.inputs.hotfix_branch_name }}"

.github/workflows/deploy-npm.yml

+25-5
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,27 @@ jobs:
5151
5252
- name: Send message to Slack channel
5353
id: slack
54-
uses: slackapi/[email protected]
54+
continue-on-error: true
55+
uses: slackapi/slack-github-action@485a9d42d3a73031f12ec201c457e2162c45d02d # v2.0.0
5556
env:
56-
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
5757
PROJECT_NAME: 'Gatsby Plugin'
5858
NPM_PACKAGE_URL: 'https://www.npmjs.com/package/gatsby-plugin-rudderstack'
59+
RELEASES_URL: 'https://github.com/rudderlabs/gatsby-plugin-rudderstack/releases/tag/v'
5960
with:
60-
channel-id: ${{ secrets.SLACK_RELEASE_CHANNEL_ID }}
61+
method: 'chat.postMessage'
62+
token: ${{ secrets.SLACK_BOT_TOKEN }}
63+
retries: rapid
64+
payload-templated: true
6165
payload: |
6266
{
67+
"channel": ${{ secrets.SLACK_RELEASE_CHANNEL_ID }},
68+
"text": "*New Release: ${{ env.PROJECT_NAME }} - <${{ env.NPM_PACKAGE_URL }}|${{ env.CURRENT_VERSION_VALUE }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SHJ20350>",
6369
"blocks": [
6470
{
6571
"type": "header",
6672
"text": {
6773
"type": "plain_text",
68-
"text": "New release: ${{ env.PROJECT_NAME }}"
74+
"text": "New Release: ${{ env.PROJECT_NAME }}"
6975
}
7076
},
7177
{
@@ -75,8 +81,22 @@ jobs:
7581
"type": "section",
7682
"text": {
7783
"type": "mrkdwn",
78-
"text": "*Release: <${{ env.NPM_PACKAGE_URL }}|${{ env.CURRENT_VERSION_VALUE }}>*\n${{ env.DATE }}"
84+
"text": "*<${{ env.NPM_PACKAGE_URL }}|v${{ env.CURRENT_VERSION_VALUE }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SW7DM8P3>"
85+
},
86+
"accessory": {
87+
"type": "image",
88+
"image_url": "https://img.icons8.com/color/452/npm.png",
89+
"alt_text": "NPM Icon"
7990
}
91+
},
92+
{
93+
"type": "context",
94+
"elements": [
95+
{
96+
"type": "mrkdwn",
97+
"text": "For more details, check the full release notes <${{ env.RELEASES_URL }}${{ env.CURRENT_VERSION_VALUE }}|here>."
98+
}
99+
]
80100
}
81101
]
82102
}

.github/workflows/draft-new-release.yml

+27-7
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,30 @@ jobs:
7676
git push
7777
7878
- name: Create pull request into main
79-
uses: repo-sync/pull-request@v2
80-
with:
81-
source_branch: ${{ steps.create-release.outputs.branch_name }}
82-
destination_branch: 'main'
83-
github_token: ${{ secrets.PAT }}
84-
pr_title: 'chore(release): pull ${{ steps.create-release.outputs.branch_name }} into main'
85-
pr_body: ':crown: *An automated PR*'
79+
env:
80+
GH_TOKEN: ${{ secrets.PAT }}
81+
run: |
82+
pr_title="chore(release): merge ${{ steps.create-release.outputs.branch_name }} into main"
83+
84+
# Create PR body with proper formatting
85+
cat > pr_body.md << EOF
86+
:crown: **Automated Release PR**
87+
88+
This pull request was created automatically by the GitHub Actions workflow. It merges the release branch (\`${{ steps.create-release.outputs.branch_name }}\`) into the \`main\` branch.
89+
90+
This ensures that the latest release branch changes are incorporated into the \`main\` branch for production.
91+
92+
### Details
93+
- **Release Version**: v${{ env.NEW_VERSION_VALUE }}
94+
- **Release Branch**: \`${{ steps.create-release.outputs.branch_name }}\`
95+
96+
---
97+
Please review and merge when ready. :rocket:
98+
EOF
99+
100+
# Create the PR using GitHub CLI
101+
gh pr create \
102+
--base main \
103+
--head ${{ steps.create-release.outputs.branch_name }} \
104+
--title "$pr_title" \
105+
--body-file pr_body.md

.github/workflows/housekeeping.yaml

+21-15
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
name: Handle stale PRs
1+
name: Handle Stale PRs and Branches
22

33
on:
44
schedule:
5-
- cron: '42 1 * * *'
5+
- cron: '1 0 * * *' # every day at 00:01
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.sha }}
9+
cancel-in-progress: true
610

711
jobs:
812
prs:
9-
name: Clean up stale prs
13+
name: Clean up stale PRs
1014
runs-on: ubuntu-latest
1115

1216
permissions:
@@ -16,26 +20,28 @@ jobs:
1620
steps:
1721
- uses: actions/stale@v9
1822
with:
19-
repo-token: ${{ github.token }}
23+
repo-token: ${{ secrets.GITHUB_TOKEN }}
2024
operations-per-run: 200
21-
stale-pr-message: 'This PR is considered to be stale. It has been open 20 days with no further activity thus it is going to be closed in 10 days. To avoid such a case please consider removing the stale label manually or add a comment to the PR.'
25+
stale-pr-message: "Hello! This PR has been open for 20 days without any activity. Therefore, it's considered as stale and is scheduled to be closed in 10 days. If you're still working on this, please remove the 'Stale' label or add a comment to keep it open. Thanks for your contribution!"
2226
days-before-pr-stale: 20
2327
days-before-pr-close: 10
2428
stale-pr-label: 'Stale'
29+
ascending: true
2530

2631
branches:
27-
name: Cleanup old branches
32+
name: Clean up stale branches
2833
runs-on: ubuntu-latest
2934
steps:
3035
- name: Checkout repository
3136
uses: actions/checkout@v4
32-
33-
- name: Run delete-old-branches-action
34-
uses: beatlabs/[email protected]
3537
with:
36-
repo_token: ${{ github.token }}
37-
date: '2 months ago'
38-
dry_run: false
39-
delete_tags: false
40-
extra_protected_branch_regex: ^(main|develop)$
41-
exclude_open_pr_branches: true
38+
fetch-depth: 0
39+
40+
- name: Run branch cleanup script
41+
env:
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
run: |
44+
chmod +x ./scripts/cleanup-old-branches.sh
45+
./scripts/cleanup-old-branches.sh \
46+
--months 2 \
47+
--protected-branches "^(main|develop)$"

.github/workflows/publish-new-release.yml

+42-29
Original file line numberDiff line numberDiff line change
@@ -52,49 +52,57 @@ jobs:
5252
npx conventional-github-releaser -p angular
5353
echo "DATE=$(date)" >> $GITHUB_ENV
5454
55-
- name: Create pull request into staging
56-
uses: repo-sync/pull-request@v2
57-
with:
58-
source_branch: 'main'
59-
destination_branch: 'develop'
60-
github_token: ${{ secrets.PAT }}
61-
pr_title: 'chore(release): pull main into develop post release v${{ steps.extract-version.outputs.release_version }}'
62-
pr_body: ':crown: *An automated PR*'
63-
pr_reviewer: 'rudderlabs/js-sdk'
64-
65-
- name: Delete hotfix release branch
66-
uses: koj-co/delete-merged-action@master
67-
if: startsWith(github.event.pull_request.head.ref, 'hotfix-release/')
68-
with:
69-
branches: 'hotfix-release/*'
55+
- name: Create pull request into develop
56+
if: always()
57+
continue-on-error: true
7058
env:
71-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
GH_TOKEN: ${{ secrets.PAT }}
60+
run: |
61+
pr_title="chore(release): merge main into develop after release v${{ steps.extract-version.outputs.release_version }}"
62+
63+
# Create PR body with proper formatting
64+
cat > pr_body.md << EOF
65+
:crown: **Automated Post-Release PR**
7266
73-
- name: Delete release branch
74-
uses: koj-co/delete-merged-action@master
75-
if: startsWith(github.event.pull_request.head.ref, 'release/')
76-
with:
77-
branches: 'release/*'
78-
env:
79-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
This pull request was created automatically by the GitHub Actions workflow. It merges changes from the \`main\` branch into the \`develop\` branch after a release has been completed.
68+
69+
This ensures that the \`develop\` branch stays up to date with all release-related changes from the \`main\` branch.
70+
71+
### Details
72+
- **Release Version**: v${{ steps.extract-version.outputs.release_version }}
73+
74+
---
75+
Please review and merge it before closing the release ticket. :rocket:
76+
EOF
77+
78+
# Create the PR using GitHub CLI
79+
gh pr create \
80+
--base develop \
81+
--head main \
82+
--title "$pr_title" \
83+
--body-file pr_body.md
8084
8185
- name: Send message to Slack channel
8286
id: slack
83-
uses: slackapi/slack-github-action@v1.27.0
87+
uses: slackapi/slack-github-action@485a9d42d3a73031f12ec201c457e2162c45d02d # v2.0.0
8488
env:
85-
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
86-
PROJECT_NAME: 'Gatsby Rudderstack Plugin'
89+
PROJECT_NAME: 'Gatsby Plugin'
8790
RELEASES_URL: 'https://github.com/rudderlabs/gatsby-plugin-rudderstack/releases/'
8891
with:
89-
channel-id: ${{ secrets.SLACK_RELEASE_CHANNEL_ID }}
92+
method: 'chat.postMessage'
93+
token: ${{ secrets.SLACK_BOT_TOKEN }}
94+
retries: rapid
95+
payload-templated: true
9096
payload: |
9197
{
98+
"channel": ${{ secrets.SLACK_RELEASE_CHANNEL_ID }},
99+
"text": "*New Release: ${{ env.PROJECT_NAME }} - <${{env.RELEASES_URL}}${{ steps.extract-version.outputs.release_version }}|v${{ steps.extract-version.outputs.release_version }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SHJ20350>",
92100
"blocks": [
93101
{
94102
"type": "header",
95103
"text": {
96104
"type": "plain_text",
97-
"text": "New release: ${{ env.PROJECT_NAME }}"
105+
"text": "New Release: ${{ env.PROJECT_NAME }}"
98106
}
99107
},
100108
{
@@ -104,7 +112,12 @@ jobs:
104112
"type": "section",
105113
"text": {
106114
"type": "mrkdwn",
107-
"text": "*Release: <${{env.RELEASES_URL}}${{ steps.extract-version.outputs.release_version }}|v${{ steps.extract-version.outputs.release_version }}>*\n${{ env.DATE }}"
115+
"text": "*<${{env.RELEASES_URL}}${{ steps.extract-version.outputs.release_version }}|v${{ steps.extract-version.outputs.release_version }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SHJ20350>"
116+
},
117+
"accessory": {
118+
"type": "image",
119+
"image_url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png",
120+
"alt_text": "GitHub Icon"
108121
}
109122
}
110123
]

.github/workflows/test.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ jobs:
3535
3636
- name: Fix filesystem paths in generated reports
3737
run: |
38-
sed -i 's+/home/runner/work/gatsby-plugin-rudderstack/gatsby-plugin-rudderstack+/github/workspace+g' reports/eslint.json
38+
sed -i 's+/home/runner/work/gatsby-plugin-rudderstack/gatsby-plugin-rudderstack++g' reports/eslint.json
3939
40-
- name: SonarCloud Scan
41-
uses: SonarSource/sonarcloud-github-action@master
40+
- name: SonarQube Scan
41+
uses: SonarSource/sonarqube-scan-action@aa494459d7c39c106cc77b166de8b4250a32bb97 # v5.1.0
4242
env:
4343
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4444
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

scripts/cleanup-old-branches.sh

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
3+
# Script to cleanup old branches that haven't been modified in the last 2 months
4+
# Requires GitHub CLI (gh) to be installed and authenticated
5+
6+
set -e
7+
8+
# Default values
9+
MONTHS_OLD=2
10+
PROTECTED_BRANCHES="^(main|develop)$"
11+
12+
# Parse arguments
13+
while [[ $# -gt 0 ]]; do
14+
case $1 in
15+
--months)
16+
MONTHS_OLD="$2"
17+
shift 2
18+
;;
19+
--protected-branches)
20+
PROTECTED_BRANCHES="$2"
21+
shift 2
22+
;;
23+
*)
24+
echo "Unknown parameter: $1"
25+
exit 1
26+
;;
27+
esac
28+
done
29+
30+
# Calculate the cutoff date (2 months ago)
31+
if [[ "$OSTYPE" == "darwin"* ]]; then
32+
# macOS date command
33+
CUTOFF_DATE=$(date -v-${MONTHS_OLD}m +%Y-%m-%d)
34+
else
35+
# GNU date command
36+
CUTOFF_DATE=$(date -d "${MONTHS_OLD} months ago" +%Y-%m-%d)
37+
fi
38+
39+
echo "Starting branch cleanup process..."
40+
echo "Cutoff date: ${CUTOFF_DATE}"
41+
echo "Protected branches pattern: ${PROTECTED_BRANCHES}"
42+
43+
# Get all remote branches
44+
BRANCHES=$(git branch -r | grep -v "HEAD" | sed 's/origin\///')
45+
46+
# Counter for deleted branches
47+
DELETED_COUNT=0
48+
49+
for BRANCH in $BRANCHES; do
50+
# Skip protected branches
51+
if echo "$BRANCH" | grep -qE "$PROTECTED_BRANCHES"; then
52+
echo "Skipping protected branch: $BRANCH"
53+
continue
54+
fi
55+
56+
# Get the last commit date for the branch
57+
LAST_COMMIT_DATE=$(git log -1 --format=%cd --date=short origin/$BRANCH)
58+
59+
# Skip if branch has open PRs
60+
if gh pr list --head "$BRANCH" --state open --json number | grep -q "number"; then
61+
echo "Skipping branch with open PR: $BRANCH"
62+
continue
63+
fi
64+
65+
# Compare dates
66+
if [[ "$LAST_COMMIT_DATE" < "$CUTOFF_DATE" ]]; then
67+
echo "Deleting branch: $BRANCH (last commit: $LAST_COMMIT_DATE)"
68+
git push origin --delete "$BRANCH" || {
69+
echo "Failed to delete branch: $BRANCH"
70+
continue
71+
}
72+
((DELETED_COUNT++))
73+
fi
74+
done
75+
76+
echo "Branch cleanup completed."
77+
echo "Total branches deleted: $DELETED_COUNT"

0 commit comments

Comments
 (0)