Skip to content

Commit b2e4d4f

Browse files
authored
feat: add GitHub actions updater + major testing framework (#35)
* fix: refactored lint pipeline, added black * fix: adhering to new script convention * feat: testing framework * fix: better github ui output
1 parent 91aaa50 commit b2e4d4f

35 files changed

+1173
-118
lines changed

.github/workflows/lint.yml

Lines changed: 84 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -6,119 +6,130 @@ on:
66
- main
77
workflow_call:
88

9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
913
permissions:
1014
contents: read
1115

16+
env:
17+
PYTHON_VERSION: '3.14'
18+
CSPELL_VERSION: '8.0.0'
19+
BLACK_VERSION: '24.10.0'
20+
PRETTIER_VERSION: '3.3.3'
21+
COMMITLINT_CLI_VERSION: '20.2.0'
22+
1223
jobs:
13-
commitlint:
14-
name: Commits
24+
install-commitlint:
1525
runs-on: ubuntu-latest
16-
1726
steps:
18-
- name: Checkout code
27+
- &checkout-code
28+
name: Checkout code (shallow)
1929
uses: actions/checkout@v5
20-
with:
21-
fetch-depth: 0
22-
fetch-tags: true
2330

24-
- name: Get current year and month for caching
25-
id: date
26-
run: echo "month_year=$(date +'%m-%Y')" >> $GITHUB_OUTPUT
27-
28-
- name: Cache commitlint tools
31+
- &cache-commitlint
32+
name: Cache Commitlint
2933
id: cache-commitlint
3034
uses: actions/cache@v4
3135
with:
32-
path: ~/.npm-commitlint
33-
key: npm-commitlint-${{ runner.os }}-${{ steps.date.outputs.month_year }}-v1
34-
restore-keys: |
35-
npm-commitlint-${{ runner.os }}-${{ steps.date.outputs.month_year }}-
36-
npm-commitlint-${{ runner.os }}-
36+
path: node_modules
37+
key: v4-commitlint-${{ env.COMMITLINT_CLI_VERSION }}
3738

38-
- name: Install commitlint and dependencies
39+
- name: Install Commitlint
3940
if: steps.cache-commitlint.outputs.cache-hit != 'true'
40-
run: |
41-
npm config set prefix ~/.npm-commitlint
42-
npm install -g \
43-
@commitlint/cli \
44-
@commitlint/config-conventional
41+
run: npm i -D @commitlint/cli@${{ env.COMMITLINT_CLI_VERSION }} @commitlint/config-conventional
4542

46-
- name: Add commitlint to PATH
47-
run: echo "$HOME/.npm-commitlint/bin" >> $GITHUB_PATH
43+
run-commitlint:
44+
runs-on: ubuntu-latest
45+
needs: install-commitlint
46+
steps:
47+
- name: Checkout code (full)
48+
uses: actions/checkout@v5
49+
with:
50+
fetch-depth: 0
4851

49-
# To avoid having a package.json maintained in this repo, we just pretend to be a Node project during the run
50-
- name: Create symlink for commitlint config
51-
run: |
52-
mkdir -p node_modules/@commitlint
53-
ln -sf ~/.npm-commitlint/lib/node_modules/@commitlint/config-conventional node_modules/@commitlint/config-conventional
52+
- *cache-commitlint
5453

55-
- name: Run commitlint on all commits
56-
run: commitlint --from origin/main --to HEAD --verbose
54+
- name: Run commitlint
55+
run: |
56+
git checkout main
57+
git checkout -
58+
./node_modules/.bin/commitlint --from main --to HEAD --verbose
5759
58-
prettier:
59-
name: Formatting
60+
install-prettier:
6061
runs-on: ubuntu-latest
61-
6262
steps:
63-
- name: Checkout code
64-
uses: actions/checkout@v5
65-
66-
- name: Get current year and month for caching
67-
id: date
68-
run: echo "month_year=$(date +'%m-%Y')" >> $GITHUB_OUTPUT
63+
- *checkout-code
6964

70-
- name: Cache prettier tools
65+
- &cache-prettier
66+
name: Cache Prettier
7167
id: cache-prettier
7268
uses: actions/cache@v4
7369
with:
74-
path: ~/.npm-prettier
75-
key: npm-prettier-${{ runner.os }}-${{ steps.date.outputs.month_year }}-v1
76-
restore-keys: |
77-
npm-prettier-${{ runner.os }}-${{ steps.date.outputs.month_year }}-
78-
npm-prettier-${{ runner.os }}-
70+
path: node_modules
71+
key: v1-prettier-${{ env.PRETTIER_VERSION }}
7972

8073
- name: Install Prettier
8174
if: steps.cache-prettier.outputs.cache-hit != 'true'
82-
run: |
83-
npm config set prefix ~/.npm-prettier
84-
npm install -g prettier
75+
run: npm i -D prettier@${{ env.PRETTIER_VERSION }}
8576

86-
- name: Add Prettier to PATH
87-
run: echo "$HOME/.npm-prettier/bin" >> $GITHUB_PATH
77+
run-prettier:
78+
runs-on: ubuntu-latest
79+
needs: install-prettier
80+
steps:
81+
- *checkout-code
82+
- *cache-prettier
8883

8984
- name: Run Prettier check
90-
run: prettier --check .
85+
run: ./node_modules/.bin/prettier --check .
9186

92-
cspell:
93-
name: Spelling
87+
run-black:
9488
runs-on: ubuntu-latest
95-
9689
steps:
97-
- name: Checkout code
98-
uses: actions/checkout@v5
90+
- *checkout-code
9991

100-
- name: Get current year and month for caching
101-
id: date
102-
run: echo "month_year=$(date +'%m-%Y')" >> $GITHUB_OUTPUT
92+
- name: Setup Python
93+
uses: actions/setup-python@v6
94+
with:
95+
python-version: '${{ env.PYTHON_VERSION }}'
96+
97+
- name: Cache Black
98+
uses: actions/cache@v4
99+
id: cache-black
100+
with:
101+
path: ~/.cache/pip
102+
key: v1-black-${{ env.BLACK_VERSION }}
103103

104-
- name: Cache cspell tools
104+
- name: Install Black
105+
run: pip install black==${{ env.BLACK_VERSION }}
106+
107+
- name: Run Black check
108+
run: black --check .
109+
110+
install-cspell:
111+
runs-on: ubuntu-latest
112+
steps:
113+
- *checkout-code
114+
115+
- &cache-cspell
116+
name: Cache CSpell
105117
id: cache-cspell
106118
uses: actions/cache@v4
107119
with:
108-
path: ~/.npm-cspell
109-
key: npm-cspell-${{ runner.os }}-${{ steps.date.outputs.month_year }}-v1
110-
restore-keys: |
111-
npm-cspell-${{ runner.os }}-${{ steps.date.outputs.month_year }}-
112-
npm-cspell-${{ runner.os }}-
120+
path: node_modules
121+
key: v1-cspell-${{ env.CSPELL_VERSION }}
113122

114123
- name: Install CSpell
115124
if: steps.cache-cspell.outputs.cache-hit != 'true'
116-
run: |
117-
npm config set prefix ~/.npm-cspell
118-
npm install -g cspell
125+
run: npm i -D cspell
119126

120-
- name: Add CSpell to PATH
121-
run: echo "$HOME/.npm-cspell/bin" >> $GITHUB_PATH
127+
run-cspell:
128+
runs-on: ubuntu-latest
129+
needs: install-cspell
130+
steps:
131+
- *checkout-code
132+
- *cache-cspell
122133

123134
- name: Run CSpell check
124-
run: cspell
135+
run: ./node_modules/.bin/cspell

.github/workflows/test.yml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: Test Actions
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- main
7+
workflow_call:
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
env:
14+
PYTHON_VERSION: '3.14'
15+
16+
jobs:
17+
python-unit-tests-actions:
18+
name: Python Unit Tests (GitHub Actions)
19+
runs-on: ubuntu-latest
20+
steps:
21+
- &checkout-code
22+
name: Checkout code
23+
uses: actions/checkout@v5
24+
25+
- &setup-python
26+
name: Setup Python
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: ${{ env.PYTHON_VERSION }}
30+
31+
- name: Install dependencies
32+
working-directory: actions
33+
run: |
34+
python -m pip install --upgrade pip
35+
pip install -r requirements.txt
36+
37+
- name: Run unit tests
38+
working-directory: actions
39+
run: python -m unittest discover -s . -p "test_*.py" -v
40+
41+
python-unit-tests-terraform:
42+
name: Python Unit Tests (Terraform)
43+
runs-on: ubuntu-latest
44+
steps:
45+
- *checkout-code
46+
- *setup-python
47+
48+
- name: Run unit tests
49+
working-directory: terraform
50+
run: python -m unittest discover -s . -p "test_*.py" -v
51+
52+
test-actions:
53+
name: Test GitHub Actions Updater
54+
runs-on: ubuntu-latest
55+
steps:
56+
- *checkout-code
57+
58+
- name: Test actions updater
59+
uses: ./actions
60+
with:
61+
dry-run: 'true'
62+
file-glob: 'actions/test/.github/**/*.yml'
63+
64+
test-circleci-orbs:
65+
name: Test CircleCI Orbs Updater
66+
runs-on: ubuntu-latest
67+
steps:
68+
- *checkout-code
69+
70+
- name: Test CircleCI orbs updater
71+
uses: ./circleci-orbs
72+
with:
73+
dry-run: 'true'
74+
circleci-config-file: 'circleci-orbs/test/.circleci/config.yml'
75+
76+
test-golang:
77+
name: Test Go Dependencies Updater
78+
runs-on: ubuntu-latest
79+
steps:
80+
- *checkout-code
81+
82+
- name: Setup test fixtures
83+
run: |
84+
cp golang/test/go.mod .
85+
cp golang/test/go.sum .
86+
87+
- name: Test Go dependencies updater
88+
uses: ./golang
89+
with:
90+
dry-run: 'true'
91+
92+
test-npm:
93+
name: Test NPM Dependencies Updater
94+
runs-on: ubuntu-latest
95+
steps:
96+
- *checkout-code
97+
98+
- name: Setup test fixtures
99+
run: |
100+
cp npm/test/package.json .
101+
cp npm/test/package-lock.json .
102+
cp npm/test/.nvmrc .
103+
104+
- name: Test NPM dependencies updater
105+
uses: ./npm
106+
with:
107+
dry-run: 'true'
108+
109+
test-terraform:
110+
name: Test Terraform Dependencies Updater
111+
runs-on: ubuntu-latest
112+
steps:
113+
- *checkout-code
114+
115+
- name: Test Terraform dependencies updater
116+
uses: ./terraform
117+
with:
118+
dry-run: 'true'
119+
working-dir: 'terraform/test'
120+
var-file-path: 'test.tfvars'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea/
22
.DS_Store
33
.venv/
4+
*.pyc

actions/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Update GitHub Actions :arrows_counterclockwise:
2+
3+
This GitHub Action scans `.github` workflows, finds `uses:` entries that match configured prefixes, compares them to the
4+
latest GitHub releases, and updates them when newer versions exist.
5+
6+
## :rocket: Usage
7+
8+
```yaml
9+
name: Update GitHub Actions
10+
on:
11+
schedule:
12+
- cron: '0 2 * * 1'
13+
workflow_dispatch:
14+
15+
jobs:
16+
update-actions:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Update GitHub Actions
20+
uses: alchemaxinc/update-deps/actions@v1
21+
with:
22+
token: ${{ github.token }}
23+
base-branch: 'main'
24+
branch-prefix: 'update-actions'
25+
pr-title: 'Update GitHub Actions'
26+
commit-message: 'Update GitHub Actions'
27+
file-glob: '.github/**/*.yml'
28+
prefixes: 'actions'
29+
```
30+
31+
## :computer: Local CLI
32+
33+
```bash
34+
python cli.py --root /path/to/repo --file-glob '.github/**/*.yml' --prefixes 'actions'
35+
```
36+
37+
## :gear: Inputs
38+
39+
| Input | Description | Required | Default |
40+
| ---------------- | --------------------------------------------------- | ------------------ | ----------------------- |
41+
| `base-branch` | Base branch for the pull request | :white_check_mark: | `main` |
42+
| `token` | GitHub token for authentication | :x: | `${{ github.token }}` |
43+
| `branch-prefix` | Prefix for the update branch | :x: | `update-actions` |
44+
| `pr-title` | Title for the pull request | :x: | `Update GitHub Actions` |
45+
| `commit-message` | Commit message for the update | :x: | `Update GitHub Actions` |
46+
| `file-glob` | Glob for workflow files (relative to repo root) | :x: | `.github/**/*.yml` |
47+
| `prefixes` | Comma-separated list of action prefixes to include | :x: | `actions` |
48+
| `auto-merge` | Wether automatic merge should be enabled for the PR | :x: | `false` |
49+
50+
## :warning: Prerequisites
51+
52+
- Workflow files must be under `.github` and match the configured `file-glob`
53+
- The action requires write permissions to create branches and pull requests
54+
- GitHub CLI must be available in the runner environment

0 commit comments

Comments
 (0)