-
Notifications
You must be signed in to change notification settings - Fork 12
182 lines (157 loc) · 6.58 KB
/
Copy pathbump.yaml
File metadata and controls
182 lines (157 loc) · 6.58 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
name: Bump the versions
on:
workflow_dispatch:
inputs:
version:
description: "What to bump?"
required: true
default: "patch"
type: choice
options:
- "patch"
- "minor"
- "major"
concurrency:
group: bump-version-${{ github.ref_name }}
cancel-in-progress: false
jobs:
bump:
permissions:
id-token: write # Needed to federate tokens.
runs-on: ubuntu-latest
steps:
- uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80
id: octo-sts
with:
scope: DataDog/build-plugins
audience: dd-octo-sts
policy: self.bump
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0 # Needed for "yarn version" to work.
token: ${{ steps.octo-sts.outputs.token }}
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: "package.json"
- name: Install dependencies
run: yarn install --immutable --immutable-cache
- name: Bump version
run: yarn version:all ${{ inputs.version }}
- name: Add files
run: git add .
- name: Variables
id: vars
run: |
VERSION=$(yarn info @datadog/build-plugins --json | jq -r '.children.Version')
echo "Version: $VERSION"
TAG_NAME="v$VERSION"
echo "Tag name: $TAG_NAME"
CURRENT_BRANCH_NAME="${{ github.head_ref || github.ref_name }}"
echo "Current branch name: $CURRENT_BRANCH_NAME"
BRANCH_NAME="bump-version-$TAG_NAME"
echo "Branch name: $BRANCH_NAME"
# Outputs for the next steps.
echo "current_branch_name=$CURRENT_BRANCH_NAME" >> $GITHUB_OUTPUT
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Check remote refs
run: |
set -euo pipefail
if git ls-remote --exit-code --heads origin "${{ steps.vars.outputs.branch_name }}" > /dev/null; then
echo "::error::Remote branch '${{ steps.vars.outputs.branch_name }}' already exists. Delete it if this is a stale failed bump, or inspect it if another bump is in progress."
exit 1
fi
if git ls-remote --exit-code --tags origin "${{ steps.vars.outputs.tag_name }}" > /dev/null; then
echo "::error::Remote tag '${{ steps.vars.outputs.tag_name }}' already exists. Delete it only if it belongs to a failed bump run."
exit 1
fi
- name: Configure git
run: |
# Set the git user.
git config --global user.name 'Bumper Bot'
git config --global user.email '200755185+dd-octo-sts[bot]@users.noreply.github.com'
- name: Create commit
run: |
echo "Checking out branch ${{ steps.vars.outputs.branch_name }}..."
git checkout -b ${{ steps.vars.outputs.branch_name }}
echo "Committing..."
git commit -m ${{ steps.vars.outputs.tag_name }} --no-verify
env:
GITHUB_TOKEN: ${{ steps.octo-sts.outputs.token }}
- name: Create remote branch
id: create-branch
run: |
echo "Pushing branch ${{ steps.vars.outputs.branch_name }}..."
# The signed-commit action expects the remote branch to exist, but it
# should recreate the local bump commit itself so GitHub verifies it.
git push origin HEAD~1:refs/heads/${{ steps.vars.outputs.branch_name }}
echo "created=true" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ steps.octo-sts.outputs.token }}
- name: Push commit
uses: Asana/push-signed-commits@d615ca88d8e1a946734c24970d1e7a6c56f34897
with:
github-token: ${{ steps.octo-sts.outputs.token }}
local_branch_name: ${{ steps.vars.outputs.branch_name }}
remote_name: origin
remote_branch_name: ${{ steps.vars.outputs.branch_name }}
- name: Create tag
id: create-tag
run: |
echo "Creating tag..."
git tag -a ${{ steps.vars.outputs.tag_name }} -m ${{ steps.vars.outputs.tag_name }}
echo "Pushing tag..."
git push origin ${{ steps.vars.outputs.tag_name }}
echo "created=true" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ steps.octo-sts.outputs.token }}
- name: Create PR
run: |
echo "Creating PR..."
TITLE="[bot] Bump versions to \`${{ steps.vars.outputs.tag_name }}\`"
PR_URL=$(gh pr create \
--title "$TITLE" \
--body "This PR bumps the package versions to \`${{ steps.vars.outputs.tag_name }}\`" \
--base "${{ steps.vars.outputs.current_branch_name }}" \
--head "${{ steps.vars.outputs.branch_name }}")
OUTPUT="### PR Created\n**[$TITLE]($PR_URL)**"
echo -e "$OUTPUT" >> $GITHUB_STEP_SUMMARY
env:
GITHUB_TOKEN: ${{ steps.octo-sts.outputs.token }}
- name: Log bump
if: success()
continue-on-error: true
run: |
HEADERS=(
-H "Content-Type: application/json"
-H "X-Datadog-Origin: build-plugins"
-H "DD-API-KEY: $DATADOG_API_KEY"
)
DATA="{
\"ddsource\": \"github\",
\"service\": \"build-plugins\",
\"message\": \"Version bumped: ${{ steps.vars.outputs.version }}\",
\"status\": \"success\",
\"env\": \"production\",
\"team\": \"language-foundations\",
\"version\": \"${{ steps.vars.outputs.version }}\"
}"
URL="https://http-intake.logs.datadoghq.com/api/v2/logs"
curl -X POST "${HEADERS[@]}" -d "$DATA" "$URL"
env:
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}
- name: Cleanup failed bump refs
if: failure()
run: |
set -euo pipefail
if [[ "${{ steps.create-tag.outputs.created }}" == "true" ]]; then
echo "Deleting tag ${{ steps.vars.outputs.tag_name }} created by this run..."
git push --delete origin ${{ steps.vars.outputs.tag_name }} || true
fi
if [[ "${{ steps.create-branch.outputs.created }}" == "true" ]]; then
echo "Deleting branch ${{ steps.vars.outputs.branch_name }} created by this run..."
git push --delete origin ${{ steps.vars.outputs.branch_name }} || true
fi
env:
GITHUB_TOKEN: ${{ steps.octo-sts.outputs.token }}