-
Notifications
You must be signed in to change notification settings - Fork 15
140 lines (121 loc) · 5.15 KB
/
Copy pathupdate-dep-version.yml
File metadata and controls
140 lines (121 loc) · 5.15 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
name: Update Dependency Version
on:
workflow_dispatch:
inputs:
repo:
description: "Repository. e.g. longhorn/go-spdk-helper"
required: true
branch:
description: "Branch to update in longhorn/dep-versions"
required: true
commit:
description: "Commit ID to tag"
required: true
tag:
description: "Tag name"
required: true
jobs:
update-version:
runs-on: ubuntu-latest
steps:
- id: app-token
uses: actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2
with:
app-id: ${{ secrets.LONGHORN_GITHUB_BOT_APP_ID }}
private-key: ${{ secrets.LONGHORN_GITHUB_BOT_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
permission-actions: write
permission-contents: write
permission-pull-requests: write
- name: Set variables
id: vars
run: |
REPO="${{ github.event.inputs.repo }}"
COMMIT="${{ github.event.inputs.commit }}"
TAG="${{ github.event.inputs.tag }}"
BRANCH="${{ github.event.inputs.branch }}"
# Extract repo name from full repo path (e.g., longhorn/go-spdk-helper -> go-spdk-helper)
NAME="${REPO##*/}"
echo "repo=$REPO" >> $GITHUB_OUTPUT
echo "commit=$COMMIT" >> $GITHUB_OUTPUT
echo "tag=$TAG" >> $GITHUB_OUTPUT
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
echo "name=$NAME" >> $GITHUB_OUTPUT
- name: Create and push tag
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
set -eux
REPO="${{ steps.vars.outputs.repo }}"
COMMIT="${{ steps.vars.outputs.commit }}"
TAG="${{ steps.vars.outputs.tag }}"
# Verify the commit exists
if ! gh api "repos/$REPO/commits/$COMMIT" > /dev/null 2>&1; then
echo "Error: Commit $COMMIT does not exist in $REPO"
exit 1
fi
# Check if the tag already exists
if gh api "repos/$REPO/git/refs/tags/$TAG" > /dev/null 2>&1; then
echo "Error: Tag $TAG already exists in $REPO"
exit 1
fi
# Create annotated tag object
TAG_SHA=$(gh api \
--method POST \
"repos/$REPO/git/tags" \
-f tag="$TAG" \
-f message="Automated tag creation: $TAG for commit $COMMIT" \
-f object="$COMMIT" \
-f type="commit" \
--jq '.sha')
# Create tag reference
gh api \
--method POST \
"repos/$REPO/git/refs" \
-f ref="refs/tags/$TAG" \
-f sha="$TAG_SHA"
echo "Successfully created and pushed tag $TAG at commit $COMMIT"
- name: Checkout dep-versions repo
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
repository: longhorn/dep-versions
ref: ${{ github.event.inputs.branch }}
token: ${{ steps.app-token.outputs.token }}
path: dep-versions
fetch-depth: 0
- name: Update versions.json
working-directory: dep-versions
run: |
set -eux
NAME="${{ steps.vars.outputs.name }}"
COMMIT="${{ steps.vars.outputs.commit }}"
TAG="${{ steps.vars.outputs.tag }}"
# Update the JSON file
jq --arg name "$NAME" --arg commit "$COMMIT" --arg tag "$TAG" \
'.[$name] |= (.commit = $commit | .tag = $tag)' \
versions.json > versions.json.tmp && mv versions.json.tmp versions.json
echo "Updated versions.json for $NAME"
- name: Create Pull Request
id: create-pull-request
uses: peter-evans/create-pull-request@22a9089034f40e5a961c8808d113e2c98fb63676 # v7
with:
token: ${{ steps.app-token.outputs.token }}
path: dep-versions
branch: "update-${{ steps.vars.outputs.name }}-${{ steps.vars.outputs.tag }}"
base: ${{ github.event.inputs.branch }}
delete-branch: true
sign-commits: true
signoff: true
author: Longhorn GitHub Bot <67932897+longhorn-io-github-bot@users.noreply.github.com>
committer: Longhorn GitHub Bot <67932897+longhorn-io-github-bot@users.noreply.github.com>
commit-message: "chore(version): update ${{ steps.vars.outputs.name }} to ${{ steps.vars.outputs.tag }} (${{ steps.vars.outputs.commit }})"
title: "chore(version): update ${{ steps.vars.outputs.name }} to ${{ steps.vars.outputs.tag }}"
body: |
## Dependency Update
Repository: ${{ steps.vars.outputs.repo }}
Component: ${{ steps.vars.outputs.name }}
New Tag: ${{ steps.vars.outputs.tag }}`
Commit: ${{ steps.vars.outputs.commit }}
Target Branch: ${{ github.event.inputs.branch }}
This PR updates the version information in versions.json for the ${{ steps.vars.outputs.name }} component.
This PR was automatically created by the Update Dependency Version workflow.