Skip to content

Commit e6ac352

Browse files
emdnetoDylanRussell
authored andcommitted
infra: Automate SHA procedure during releases (open-telemetry#4547)
* trying sha-automation Signed-off-by: emdneto <[email protected]> * fix label names * fix sha-automation core Signed-off-by: emdneto <[email protected]> * add new line Signed-off-by: emdneto <[email protected]> --------- Signed-off-by: emdneto <[email protected]>
1 parent 9ee6872 commit e6ac352

10 files changed

+101
-14
lines changed

.github/workflows/contrib.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ jobs:
1515
uses: open-telemetry/opentelemetry-python-contrib/.github/workflows/core_contrib_test_0.yml@main
1616
with:
1717
CORE_REPO_SHA: ${{ github.sha }}
18-
CONTRIB_REPO_SHA: main
18+
CONTRIB_REPO_SHA: ${{ github.event_name == 'pull_request' && (
19+
contains(github.event.pull_request.labels.*.name, 'prepare-release') && github.event.pull_request.head.ref ||
20+
contains(github.event.pull_request.labels.*.name, 'backport') && github.event.pull_request.base.ref ||
21+
'main'
22+
) || 'main' }}

.github/workflows/lint_0.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@ concurrency:
1515

1616
env:
1717
CORE_REPO_SHA: main
18-
CONTRIB_REPO_SHA: main
18+
# Set the SHA to the branch name if the PR has a label 'prepare-release' or 'backport' otherwise, set it to 'main'
19+
# For PRs you can change the inner fallback ('main')
20+
# For pushes you change the outer fallback ('main')
21+
# The logic below is used during releases and depends on having an equivalent branch name in the contrib repo.
22+
CONTRIB_REPO_SHA: ${{ github.event_name == 'pull_request' && (
23+
contains(github.event.pull_request.labels.*.name, 'prepare-release') && github.event.pull_request.head.ref ||
24+
contains(github.event.pull_request.labels.*.name, 'backport') && github.event.pull_request.base.ref ||
25+
'main'
26+
) || 'main' }}
1927
PIP_EXISTS_ACTION: w
2028

2129
jobs:

.github/workflows/misc_0.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@ concurrency:
1515

1616
env:
1717
CORE_REPO_SHA: main
18-
CONTRIB_REPO_SHA: main
18+
# Set the SHA to the branch name if the PR has a label 'prepare-release' or 'backport' otherwise, set it to 'main'
19+
# For PRs you can change the inner fallback ('main')
20+
# For pushes you change the outer fallback ('main')
21+
# The logic below is used during releases and depends on having an equivalent branch name in the contrib repo.
22+
CONTRIB_REPO_SHA: ${{ github.event_name == 'pull_request' && (
23+
contains(github.event.pull_request.labels.*.name, 'prepare-release') && github.event.pull_request.head.ref ||
24+
contains(github.event.pull_request.labels.*.name, 'backport') && github.event.pull_request.base.ref ||
25+
'main'
26+
) || 'main' }}
1927
PIP_EXISTS_ACTION: w
2028

2129
jobs:

.github/workflows/prepare-patch-release.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ jobs:
6565
run: .github/scripts/use-cla-approved-github-bot.sh
6666

6767
- name: Create pull request
68+
id: create_pr
6869
env:
6970
# not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
7071
GITHUB_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
@@ -74,7 +75,15 @@ jobs:
7475
7576
git commit -a -m "$message"
7677
git push origin HEAD:$branch
77-
gh pr create --title "[$GITHUB_REF_NAME] $message" \
78+
pr_url=$(gh pr create --title "[$GITHUB_REF_NAME] $message" \
7879
--body "$message." \
7980
--head $branch \
80-
--base $GITHUB_REF_NAME
81+
--base $GITHUB_REF_NAME)
82+
83+
echo "pr_url=$pr_url" >> $GITHUB_OUTPUT
84+
- name: Add prepare-release label to PR
85+
if: steps.create_pr.outputs.pr_url != ''
86+
env:
87+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88+
run: |
89+
gh pr edit ${{ steps.create_pr.outputs.pr_url }} --add-label "prepare-release"

.github/workflows/prepare-release-branch.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ jobs:
9191
run: .github/scripts/use-cla-approved-github-bot.sh
9292

9393
- name: Create pull request against the release branch
94+
id: create_release_branch_pr
9495
env:
9596
# not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
9697
GITHUB_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
@@ -100,10 +101,18 @@ jobs:
100101
101102
git commit -a -m "$message"
102103
git push origin HEAD:$branch
103-
gh pr create --title "[$RELEASE_BRANCH_NAME] $message" \
104+
pr_url=$(gh pr create --title "[$RELEASE_BRANCH_NAME] $message" \
104105
--body "$message." \
105106
--head $branch \
106-
--base $RELEASE_BRANCH_NAME
107+
--base $RELEASE_BRANCH_NAME)
108+
echo "pr_url=$pr_url" >> $GITHUB_OUTPUT
109+
110+
- name: Add prepare-release label to PR
111+
if: steps.create_release_branch_pr.outputs.pr_url != ''
112+
env:
113+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
114+
run: |
115+
gh pr edit ${{ steps.create_release_branch_pr.outputs.pr_url }} --add-label "prepare-release"
107116
108117
create-pull-request-against-main:
109118
runs-on: ubuntu-latest
@@ -170,6 +179,7 @@ jobs:
170179
run: .github/scripts/use-cla-approved-github-bot.sh
171180

172181
- name: Create pull request against main
182+
id: create_main_pr
173183
env:
174184
# not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
175185
GITHUB_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
@@ -180,7 +190,15 @@ jobs:
180190
181191
git commit -a -m "$message"
182192
git push origin HEAD:$branch
183-
gh pr create --title "$message" \
193+
pr_url=$(gh pr create --title "$message" \
184194
--body "$body" \
185195
--head $branch \
186-
--base main
196+
--base main)
197+
echo "pr_url=$pr_url" >> $GITHUB_OUTPUT
198+
199+
- name: Add prepare-release label to PR
200+
if: steps.create_main_pr.outputs.pr_url != ''
201+
env:
202+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
203+
run: |
204+
gh pr edit ${{ steps.create_main_pr.outputs.pr_url }} --add-label "prepare-release"

.github/workflows/templates/lint.yml.j2

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@ concurrency:
1515

1616
env:
1717
CORE_REPO_SHA: main
18-
CONTRIB_REPO_SHA: main
18+
# Set the SHA to the branch name if the PR has a label 'prepare-release' or 'backport' otherwise, set it to 'main'
19+
# For PRs you can change the inner fallback ('main')
20+
# For pushes you change the outer fallback ('main')
21+
# The logic below is used during releases and depends on having an equivalent branch name in the contrib repo.
22+
CONTRIB_REPO_SHA: {% raw %}${{ github.event_name == 'pull_request' && (
23+
contains(github.event.pull_request.labels.*.name, 'prepare-release') && github.event.pull_request.head.ref ||
24+
contains(github.event.pull_request.labels.*.name, 'backport') && github.event.pull_request.base.ref ||
25+
'main'
26+
) || 'main' }}{% endraw %}
1927
PIP_EXISTS_ACTION: w
2028

2129
jobs:

.github/workflows/templates/misc.yml.j2

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@ concurrency:
1515

1616
env:
1717
CORE_REPO_SHA: main
18-
CONTRIB_REPO_SHA: main
18+
# Set the SHA to the branch name if the PR has a label 'prepare-release' or 'backport' otherwise, set it to 'main'
19+
# For PRs you can change the inner fallback ('main')
20+
# For pushes you change the outer fallback ('main')
21+
# The logic below is used during releases and depends on having an equivalent branch name in the contrib repo.
22+
CONTRIB_REPO_SHA: {% raw %}${{ github.event_name == 'pull_request' && (
23+
contains(github.event.pull_request.labels.*.name, 'prepare-release') && github.event.pull_request.head.ref ||
24+
contains(github.event.pull_request.labels.*.name, 'backport') && github.event.pull_request.base.ref ||
25+
'main'
26+
) || 'main' }}{% endraw %}
1927
PIP_EXISTS_ACTION: w
2028

2129
jobs:

.github/workflows/templates/test.yml.j2

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@ concurrency:
1515

1616
env:
1717
CORE_REPO_SHA: main
18-
CONTRIB_REPO_SHA: main
18+
# Set the SHA to the branch name if the PR has a label 'prepare-release' or 'backport' otherwise, set it to 'main'
19+
# For PRs you can change the inner fallback ('main')
20+
# For pushes you change the outer fallback ('main')
21+
# The logic below is used during releases and depends on having an equivalent branch name in the contrib repo.
22+
CONTRIB_REPO_SHA: {% raw %}${{ github.event_name == 'pull_request' && (
23+
contains(github.event.pull_request.labels.*.name, 'prepare-release') && github.event.pull_request.head.ref ||
24+
contains(github.event.pull_request.labels.*.name, 'backport') && github.event.pull_request.base.ref ||
25+
'main'
26+
) || 'main' }}{% endraw %}
1927
PIP_EXISTS_ACTION: w
2028

2129
jobs:

.github/workflows/test_0.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@ concurrency:
1515

1616
env:
1717
CORE_REPO_SHA: main
18-
CONTRIB_REPO_SHA: main
18+
# Set the SHA to the branch name if the PR has a label 'prepare-release' or 'backport' otherwise, set it to 'main'
19+
# For PRs you can change the inner fallback ('main')
20+
# For pushes you change the outer fallback ('main')
21+
# The logic below is used during releases and depends on having an equivalent branch name in the contrib repo.
22+
CONTRIB_REPO_SHA: ${{ github.event_name == 'pull_request' && (
23+
contains(github.event.pull_request.labels.*.name, 'prepare-release') && github.event.pull_request.head.ref ||
24+
contains(github.event.pull_request.labels.*.name, 'backport') && github.event.pull_request.base.ref ||
25+
'main'
26+
) || 'main' }}
1927
PIP_EXISTS_ACTION: w
2028

2129
jobs:

.github/workflows/test_1.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@ concurrency:
1515

1616
env:
1717
CORE_REPO_SHA: main
18-
CONTRIB_REPO_SHA: main
18+
# Set the SHA to the branch name if the PR has a label 'prepare-release' or 'backport' otherwise, set it to 'main'
19+
# For PRs you can change the inner fallback ('main')
20+
# For pushes you change the outer fallback ('main')
21+
# The logic below is used during releases and depends on having an equivalent branch name in the contrib repo.
22+
CONTRIB_REPO_SHA: ${{ github.event_name == 'pull_request' && (
23+
contains(github.event.pull_request.labels.*.name, 'prepare-release') && github.event.pull_request.head.ref ||
24+
contains(github.event.pull_request.labels.*.name, 'backport') && github.event.pull_request.base.ref ||
25+
'main'
26+
) || 'main' }}
1927
PIP_EXISTS_ACTION: w
2028

2129
jobs:

0 commit comments

Comments
 (0)