Skip to content

Commit d5b7afa

Browse files
committed
feat: add composer composite actions
1 parent 7c2ccdd commit d5b7afa

File tree

6 files changed

+326
-33
lines changed

6 files changed

+326
-33
lines changed

README.md

Lines changed: 183 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,46 @@
1616

1717
# Shared Github Actions
1818

19-
This repository serves as a collection of reusable GitHub Action workflows specifically designed for usage in Wayofdev projects. The workflows stored here encapsulate common and repetitive tasks, allowing them to be easily integrated into multiple projects. This not only reduces the necessity to rewrite code, but also ensures a standardized approach to common operations across all Wayofdev repositories.
19+
This repository is a collection of reusable GitHub Actions workflows and composite actions, specifically designed for use in Wayofdev projects. These tools encapsulate common and repetitive tasks, allowing for easy integration into multiple projects. This approach not only reduces the need to rewrite code but also ensures standardized operations across all Wayofdev repositories.
20+
21+
Learn more about:
22+
23+
- [Reusing Workflows](https://docs.github.com/en/actions/using-workflows/reusing-workflows)
24+
- [Creating Composite Actions](https://docs.github.com/en/actions/creating-actions/creating-a-composite-action)
25+
26+
<br>
27+
28+
## 📋 Table of Contents
29+
30+
- [Getting Started](#getting-started)
31+
- [Workflows](#workflows)
32+
- [Auto Label and Release Management](#-auto-label-and-release-management)
33+
- [Docker](#-docker)
34+
- [Create Diagrams](#-create-diagrams)
35+
- [Static Analysis](#-static-analysis)
36+
- [Composite Actions](#composite-actions)
37+
- [Dependency Management](#-dependency-management)
38+
- [License](#license)
39+
- [Author Information](#author-information)
40+
- [Contributing](#want-to-contribute)
41+
42+
<br>
2043

2144
## 🚀 Getting Started
2245

23-
To use these workflows, simply reference them from your project's workflows. Instructions for each workflow are detailed below.
46+
To use these workflows and actions, reference them directly from your project's workflows. Detailed instructions for each are provided below.
47+
48+
<br>
49+
50+
## ⚡️ Workflows
2451

2552
Read more about [reusing workflows](https://docs.github.com/en/actions/using-workflows/reusing-workflows).
2653

27-
<br>
54+
### → Auto Label and Release Management
2855

29-
## 📑 Examples
56+
#### `apply-labels.yml:`
3057

31-
### `apply-labels.yml:`
58+
Automatically applies labels to pull requests based on modified paths.
3259

3360
This workflow triages pull requests and applies labels based on the paths that are modified in the pull request. This can help to categorize your pull requests and make it easier to identify the type of changes included.
3461

@@ -57,7 +84,7 @@ jobs:
5784

5885
<br>
5986

60-
### `auto-merge-release.yml:`
87+
### `auto-merge-release.yml:`
6188

6289
This workflow automatically merges releases. This workflow utilizes [peter-evans/enable-pull-request-automerge](https://github.com/peter-evans/enable-pull-request-automerge) to auto-merge releases that are created by [googleapis/release-please](https://github.com/googleapis/release-please).
6390

@@ -92,7 +119,40 @@ jobs:
92119

93120
<br>
94121

95-
### `build-image.yml:`
122+
### `create-release.yml:`
123+
124+
This workflow uses [google-github-actions/release-please-action](https://github.com/google-github-actions/release-please-action) to create automated releases based on [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/).
125+
126+
Here is an example of how to use this workflow:
127+
128+
```yaml
129+
---
130+
131+
on: # yamllint disable-line rule:truthy
132+
push:
133+
branches:
134+
- master
135+
136+
name: 📦 Create release
137+
138+
jobs:
139+
release:
140+
uses: wayofdev/gh-actions/.github/workflows/create-release.yml@master
141+
with:
142+
os: ubuntu-latest
143+
branch: master
144+
package-name: docker-php-base
145+
secrets:
146+
token: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
147+
148+
...
149+
```
150+
151+
<br>
152+
153+
### → Docker
154+
155+
### `build-image.yml:`
96156

97157
This workflow builds a docker image and pushes it to the GitHub Container Registry.
98158

@@ -205,7 +265,9 @@ jobs:
205265

206266
<br>
207267

208-
### `create-arch-diagram.yml:`
268+
### → Create Diagrams
269+
270+
### `create-arch-diagram.yml:`
209271

210272
This workflow leverages the [codesee-io/codesee-action](https://github.com/Codesee-io/codesee-action) action to automatically generate architecture diagrams for your codebase whenever a pull request is made.
211273

@@ -244,68 +306,156 @@ jobs:
244306

245307
<br>
246308

247-
### `create-release.yml:`
309+
### Static Analysis
248310

249-
This workflow uses [google-github-actions/release-please-action](https://github.com/google-github-actions/release-please-action) to create automated releases based on [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/).
311+
### `shellcheck.yml:`
312+
313+
This workflow uses [redhat-plumbers-in-action/differential-shellcheck](https://github.com/redhat-plumbers-in-action/differential-shellcheck) to run shell script analysis.
250314

251315
Here is an example of how to use this workflow:
252316

253317
```yaml
254318
---
255319

256320
on: # yamllint disable-line rule:truthy
257-
push:
258-
branches:
259-
- master
321+
pull_request:
260322

261-
name: 📦 Create release
323+
name: 🐞 Differential shell-check
324+
325+
permissions:
326+
contents: read
262327

263328
jobs:
264-
release:
265-
uses: wayofdev/gh-actions/.github/workflows/create-release.yml@master
329+
shellcheck:
330+
uses: wayofdev/gh-actions/.github/workflows/shellcheck.yml@master
266331
with:
267332
os: ubuntu-latest
268-
branch: master
269-
package-name: docker-php-base
333+
severity: warning
270334
secrets:
271-
token: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
335+
token: ${{ secrets.GITHUB_TOKEN }}
272336

273337
...
274338
```
275339

276340
<br>
277341

278-
### `shellcheck.yml:`
342+
## ⚡️ Composite Actions
279343

280-
This workflow uses [redhat-plumbers-in-action/differential-shellcheck](https://github.com/redhat-plumbers-in-action/differential-shellcheck) to run shell script analysis.
344+
Composite Actions are a powerful feature of GitHub Actions that allow you to create reusable actions using a combination of other actions, shell commands, or both. This enables you to encapsulate a sequence of steps into a single action, making your workflows more modular, easier to maintain, and reducing duplication across your projects. Composite Actions can accept inputs and use outputs, making them highly flexible and adaptable to various use cases.
281345

282-
Here is an example of how to use this workflow:
346+
### → Dependency Management
347+
348+
### `composer/install:`
349+
350+
This action installs dependencies with Composer based on the specified dependency level (`lowest`, `locked`, `highest`). It's designed to be flexible, allowing you to specify the working directory for the Composer command.
351+
352+
Here is an example of how to use this action in your existing workfow:
283353

284354
```yaml
285355
---
286356

287357
on: # yamllint disable-line rule:truthy
358+
push:
359+
branches:
360+
- master
288361
pull_request:
289362

290-
name: 🐞 Differential shell-check
363+
name: 📥 Composer Install
291364

292-
permissions:
293-
contents: read
365+
jobs:
366+
composer-install:
367+
runs-on: ${{ matrix.os }}
368+
strategy:
369+
matrix:
370+
os:
371+
- "ubuntu-latest"
372+
php-version:
373+
- "8.2"
374+
dependencies:
375+
- "locked"
376+
377+
steps:
378+
- name: 📦 Check out the codebase
379+
uses: actions/checkout@v4
380+
381+
- name: 📥 Install "${{ matrix.dependencies }}" dependencies
382+
uses: wayofdev/gh-actions/actions/composer/install@master
383+
with:
384+
dependencies: ${{ matrix.dependencies }}
385+
working-directory: '.'
386+
```
387+
388+
<br>
389+
390+
### `composer/get-cache-directory:`
391+
392+
This action determines the Composer cache directory and exports it as `COMPOSER_CACHE_DIR` environment variable. It allows you to specify the working directory for the Composer command to determine the cache directory.
393+
394+
Here is an example of how to use this action in your existing workflow:
395+
396+
```yaml
397+
---
398+
399+
on:
400+
push:
401+
branches:
402+
- master
403+
pull_request:
404+
405+
name: 🗂 Get Composer Cache Directory
294406
295407
jobs:
296-
shellcheck:
297-
uses: wayofdev/gh-actions/.github/workflows/shellcheck.yml@master
298-
with:
299-
os: ubuntu-latest
300-
severity: warning
301-
secrets:
302-
token: ${{ secrets.GITHUB_TOKEN }}
408+
get-composer-cache-dir:
409+
runs-on: ubuntu-latest
303410
304-
...
411+
steps:
412+
- name: 📦 Check out the codebase
413+
uses: actions/checkout@v4
414+
415+
- name: 🔍 Get Composer Cache Directory
416+
uses: wayofdev/gh-actions/actions/composer/get-cache-directory@master
417+
with:
418+
working-directory: '.'
305419
```
306420

307421
<br>
308422

423+
### `composer/get-root-version:`
424+
425+
This action determines the Composer root version based on the specified branch and exports it as `COMPOSER_ROOT_VERSION` environment variable. It's designed to be flexible, allowing you to specify both the branch and the working directory for the Composer command to determine the root version.
426+
427+
Here is an example of how to use this action in your existing workflow:
428+
429+
```yaml
430+
---
431+
432+
on:
433+
push:
434+
branches:
435+
- master
436+
pull_request:
437+
438+
name: 🎯 Get Composer Root Version
439+
440+
jobs:
441+
get-composer-root-version:
442+
runs-on: ubuntu-latest
443+
444+
steps:
445+
- name: 📦 Check out the codebase
446+
uses: actions/checkout@v4
447+
448+
- name: 🎯 Get Composer Root Version
449+
uses: wayofdev/gh-actions/actions/composer/get-root-version@master
450+
with:
451+
branch: master
452+
working-directory: '.'
453+
```
454+
455+
These sections are designed to seamlessly integrate with your existing `README.md` documentation, providing clear instructions on how to use the new Composer actions within GitHub workflows.
456+
457+
458+
309459
## 🤝 License
310460

311461
[![Licence](https://img.shields.io/github/license/wayofdev/gh-actions?style=for-the-badge&color=blue)](./LICENSE)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Documentation References:
2+
# - Creating a Composite Action: https://docs.github.com/en/actions/creating-actions/creating-a-composite-action
3+
# - Metadata Syntax for Inputs: https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputs
4+
# - Runs for Composite Actions: https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-composite-run-steps-actions
5+
# - Composer CLI Documentation: https://getcomposer.org/doc/03-cli.md#composer-cache-dir
6+
# - Other Implementations: https://github.com/ergebnis/.github/blob/main/actions
7+
8+
name: 🗂 Get composer cache directory
9+
description: Determines the composer cache directory and exports it as COMPOSER_CACHE_DIR environment variable
10+
11+
inputs:
12+
working-directory:
13+
default: .
14+
description: Which directory to use as working directory
15+
required: true
16+
17+
runs:
18+
using: composite
19+
20+
steps:
21+
- name: 🔍 Get composer cache directory
22+
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir --working-dir=${{ inputs.working-directory }})" >> $GITHUB_ENV
23+
shell: bash
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Documentation References:
2+
# - Creating a Composite Action: https://docs.github.com/en/actions/creating-actions/creating-a-composite-action
3+
# - Metadata Syntax for Inputs: https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputs
4+
# - Runs for Composite Actions: https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-composite-run-steps-actions
5+
# - Composer CLI Documentation: https://getcomposer.org/doc/03-cli.md#composer-root-version
6+
# - Other Implementations: https://github.com/ergebnis/.github/blob/main/actions
7+
8+
name: 🎯 Get composer root version
9+
description: Determines the composer root version and exports it as COMPOSER_ROOT_VERSION environment variable
10+
11+
inputs:
12+
branch:
13+
default: master
14+
description: Name of the branch, e.g. "master"
15+
required: true
16+
working-directory:
17+
default: "."
18+
description: Which directory to use as working directory
19+
required: true
20+
21+
runs:
22+
using: 'composite'
23+
24+
steps:
25+
- name: 🎯 Get composer root version
26+
env:
27+
COMPOSER_DETERMINE_ROOT_VERSION_BRANCH: ${{ inputs.branch }}
28+
COMPOSER_DETERMINE_ROOT_VERSION_WORKING_DIRECTORY: ${{ inputs.working-directory }}
29+
run: ${{ github.action_path }}/run.sh
30+
shell: bash
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
3+
branch="${COMPOSER_DETERMINE_ROOT_VERSION_BRANCH}"
4+
workingDirectory="${COMPOSER_DETERMINE_ROOT_VERSION_WORKING_DIRECTORY}"
5+
6+
if [[ ! -d ${workingDirectory} ]]; then
7+
echo ::error::The value for the \"working-directory\" input needs to be an existing directory. The directory \""${workingDirectory}"\" does not exist.
8+
9+
exit 1;
10+
fi
11+
12+
pathToComposerJsonFile="${COMPOSER_DETERMINE_ROOT_VERSION_WORKING_DIRECTORY}/composer.json"
13+
14+
if [[ ! -f "${pathToComposerJsonFile}" ]]; then
15+
echo ::error::A composer.json file could not be found in the directory \""${workingDirectory}"\".
16+
17+
exit 1
18+
fi
19+
20+
COMPOSER_ROOT_VERSION=$(jq --arg key "dev-${branch}" --raw-output '.["extra"]["branch-alias"][$key]' "${pathToComposerJsonFile}")
21+
22+
if [[ null = "${COMPOSER_ROOT_VERSION}" ]]; then
23+
echo ::error:A branch alias has not been defined in \""${pathToComposerJsonFile}"\" for branch \""${branch}"\".
24+
25+
exit 0
26+
fi
27+
28+
echo "COMPOSER_ROOT_VERSION=${COMPOSER_ROOT_VERSION}" >> "${GITHUB_ENV}"

0 commit comments

Comments
 (0)