Repository navigation
136 lines (119 loc) · 5.42 KB
/
Copy pathplugin-update.yml
File metadata and controls
136 lines (119 loc) · 5.42 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
name: Plugin update
run-name: Update ${{ inputs.plugin }} to v${{ inputs.version }}
on:
workflow_dispatch:
inputs:
plugin:
description: 'Full name of the plugin, e.g., vault-plugin-auth-kubernetes'
required: true
type: string
branch:
description: 'Git branch name to use'
required: true
type: string
version:
description: 'Version of the plugin with *NO* "v", e.g., 1.2.3'
required: true
type: string
reviewer:
description: 'Reviewer to tag on the PR'
required: false
type: string
jobs:
plugin-update:
runs-on: ubuntu-latest
env:
VAULT_BRANCH: ${{ inputs.branch }}
REVIEWER: ${{ inputs.reviewer || github.actor }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
# We don't use the default token so that checks are executed on the resulting PR
# https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow
token: ${{ secrets.ELEVATED_GITHUB_TOKEN }}
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
with:
cache: false # save cache space for vault builds: https://github.com/hashicorp/vault/pull/21764
go-version-file: .go-version
- name: Update plugin
if: github.repository == 'hashicorp/vault'
run: |
go get "github.com/hashicorp/${{ inputs.plugin }}@v${{ inputs.version }}"
go mod tidy
- name: Update Enterprise-only plugin
if: github.repository == 'hashicorp/vault-enterprise'
env:
# Use elevated token to read private repos.
GITHUB_TOKEN: ${{secrets.ELEVATED_GITHUB_TOKEN}}
GOPRIVATE: github.com/hashicorp/*
run: |
git config --global url."https://${GITHUB_TOKEN}@github.com/".insteadOf "https://github.com/"
(cd vault_ent && go get "github.com/hashicorp/${{ inputs.plugin }}@v${{ inputs.version }}" && go mod tidy)
go mod tidy
- name: Detect changes
run: |
count=$(git status --porcelain=v1 2>/dev/null | wc -l)
if [ "$count" -eq 0 ]; then
echo "::error::no updates were made for ${{ inputs.plugin }} with tag v${{ inputs.version }}"
exit 1
fi
- name: Commit and push
run: |
git config user.name hc-github-team-secure-vault-ecosystem
git config user.email hc-github-team-secure-vault-ecosystem@users.noreply.github.com
git add go.mod go.sum
git commit -m "Update ${{ inputs.plugin }} to v${{ inputs.version }}"
git push -f origin ${{ github.ref_name }}:"$VAULT_BRANCH"
- name: Open pull request if needed
id: pr
env:
GITHUB_TOKEN: ${{secrets.ELEVATED_GITHUB_TOKEN}}
# Only open a PR if the branch is not attached to an existing one
run: |
PR=$(gh pr list --head "$VAULT_BRANCH" --json number -q '.[0].number')
if [ -z "$PR" ]; then
gh pr create \
--head "$VAULT_BRANCH" \
--reviewer "$REVIEWER" \
--assignee "$REVIEWER" \
--title "Update ${{ inputs.plugin }} to v${{ inputs.version }}" \
--body "This PR was generated by a GitHub Action. Full log: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
echo "vault_pr_num=$(gh pr list --head "$VAULT_BRANCH" --json number -q '.[0].number')" >> "$GITHUB_OUTPUT"
echo "vault_pr_url=$(gh pr list --head "$VAULT_BRANCH" --json url -q '.[0].url')" >> "$GITHUB_OUTPUT"
else
echo "::notice::Pull request $PR already exists, won't create a new one."
fi
- name: Add changelog
if: steps.pr.outputs.vault_pr_num != ''
run: |
PLUGIN="${{ inputs.plugin }}"
# plugin type is one of auth/secrets/database
PLUGIN_TYPE=$(echo "$PLUGIN" | awk -F- '{print $3}')
echo "::debug::plugin type: $PLUGIN_TYPE"
# plugin service is the rest of the repo name
PLUGIN_SERVICE=$(echo "$PLUGIN" | cut -d- -f 4-)
echo "::debug::plugin service: $PLUGIN_SERVICE"
# changelog filename is the PR number with a .txt extension
# if the repo is vault-enterprise, the filename should start with an underscore
CHANGELOG_FILENAME="${{ steps.pr.outputs.vault_pr_num }}.txt"
if [ "${{ github.repository }}" = "hashicorp/vault-enterprise" ]; then
CHANGELOG_FILENAME="_${{ steps.pr.outputs.vault_pr_num }}.txt"
fi
echo "::debug::changelog filename: $CHANGELOG_FILENAME"
echo "\`\`\`release-note:change
${PLUGIN_TYPE}/${PLUGIN_SERVICE}: Update plugin to v${{ inputs.version }}
\`\`\`" > "changelog/$CHANGELOG_FILENAME"
git add changelog/
git commit -m "Add changelog"
git push origin ${{ github.ref_name }}:"$VAULT_BRANCH"
- name: Add labels to Vault PR
if: steps.pr.outputs.vault_pr_num != ''
env:
# this is a different token to the one we have been using that should
# allow us to add labels
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
continue-on-error: true
run: |
gh pr edit "${{ steps.pr.outputs.vault_pr_num }}" \
--add-label "dependencies" \
--repo hashicorp/vault