Skip to content

Commit e017fbd

Browse files
authored
[BRE-494] - Create a Workflow that Updates the Approved Actions (#38)
1 parent 74a4a0a commit e017fbd

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
name: Update Approved Actions
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 */14 * *'
6+
7+
jobs:
8+
actions-update:
9+
name: "Update Approved Actions"
10+
runs-on: ubuntu-24.04
11+
steps:
12+
- name: Login to Azure - CI Subscription
13+
uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0
14+
with:
15+
creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }}
16+
17+
- name: Retrieve secrets
18+
id: retrieve-secrets
19+
uses: bitwarden/gh-actions/get-keyvault-secrets@main
20+
with:
21+
keyvault: "bitwarden-ci"
22+
secrets: "github-gpg-private-key,
23+
github-gpg-private-key-passphrase"
24+
25+
- name: Import GPG key
26+
uses: crazy-max/ghaction-import-gpg@cb9bde2e2525e640591a934b1fd28eef1dcaf5e5 # v6.2.0
27+
with:
28+
gpg_private_key: ${{ steps.retrieve-secrets.outputs.github-gpg-private-key }}
29+
passphrase: ${{ steps.retrieve-secrets.outputs.github-gpg-private-key-passphrase }}
30+
git_user_signingkey: true
31+
git_commit_gpgsign: true
32+
33+
- name: Setup git
34+
run: |
35+
git config --local user.email "[email protected]"
36+
git config --local user.name "bitwarden-devops-bot"
37+
38+
- name: Checkout Branch
39+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
40+
41+
- name: Set up Python 3.11
42+
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
43+
with:
44+
python-version: "3.11"
45+
46+
- name: Install bwwl binary
47+
run: python -m pip install --upgrade bitwarden_workflow_linter
48+
49+
- name: Create Branch
50+
id: create-branch
51+
run: |
52+
NAME="update-actions-$(date +'%Y%m%d-%H%M%S')"
53+
git switch -c $NAME
54+
echo "name=$NAME" >> $GITHUB_OUTPUT
55+
56+
- name: Run bwwl update
57+
run: bwwl actions update -o src/bitwarden_workflow_linter/default_actions.json
58+
59+
- name: Check if there are changes to commit
60+
id: new-changes
61+
run: |
62+
if [ -n "$(git status --porcelain)" ]; then
63+
echo "new_changes=TRUE" >> $GITHUB_OUTPUT
64+
else
65+
echo "new_changes=FALSE" >> $GITHUB_OUTPUT
66+
echo "No changes to commit!";
67+
fi
68+
69+
- name: Commit changes
70+
if: steps.new-changes.outputs.new_changes == 'TRUE'
71+
env:
72+
PR_BRANCH: ${{ steps.create-branch.outputs.name }}
73+
run: |
74+
git commit -m "Update approved actions" -a
75+
git push origin $PR_BRANCH
76+
77+
- name: Generate GH App token
78+
if: steps.new-changes.outputs.new_changes == 'TRUE'
79+
uses: actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1.11.0
80+
id: app-token
81+
with:
82+
app-id: ${{ secrets.GH_APP_ID }}
83+
private-key: ${{ secrets.GH_APP_KEY }}
84+
owner: ${{ github.repository_owner }}
85+
86+
- name: Create PR
87+
if: steps.new-changes.outputs.new_changes == 'TRUE'
88+
id: create-pr
89+
env:
90+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
91+
PR_BRANCH: ${{ steps.create-branch.outputs.name }}
92+
TITLE: "Update bwwl Approved Actions"
93+
run: |
94+
PR_URL=$(gh pr create --title "$TITLE" \
95+
--base "main" \
96+
--head "$PR_BRANCH" \
97+
--label "version:patch" \
98+
--label "automated pr" \
99+
--body "
100+
## Type of change
101+
- [ ] Bug fix
102+
- [ ] New feature development
103+
- [X] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
104+
- [ ] Build/deploy pipeline (DevOps)
105+
- [ ] Other
106+
107+
## Description
108+
- This PR updates the approved actions for the Bitwarden Workflow Linter.")
109+
echo "pr_number=${PR_URL##*/}" >> $GITHUB_OUTPUT
110+
111+
- name: Approve and Merge PR
112+
if: ${{ steps.create-pr.outcome == 'success' }}
113+
env:
114+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
115+
PR_NUMBER: ${{ steps.create-pr.outputs.pr_number }}
116+
run: |
117+
gh pr review $PR_NUMBER --approve
118+
gh pr merge $PR_NUMBER --squash --auto --delete-branch

0 commit comments

Comments
 (0)