Skip to content

Commit 5380311

Browse files
init
1 parent d17c56f commit 5380311

File tree

3 files changed

+230
-0
lines changed

3 files changed

+230
-0
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: Checkout and build code
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
TAG:
7+
description: 'Tag/commit/branch to checkout'
8+
required: false
9+
type: string
10+
default: ''
11+
PHP_VERSION:
12+
description: 'The PHP version to use'
13+
required: true
14+
type: string
15+
default: '8.2'
16+
BUILD_FOR_DEPLOY:
17+
description: 'Whether to build for deployment immediately or to keep developer tools'
18+
required: false
19+
type: boolean
20+
default: false
21+
ARTIFACT_NAME:
22+
description: 'The artifact to deploy'
23+
required: false
24+
type: string
25+
default: 'compressed-code-artifact'
26+
27+
jobs:
28+
checkout-and-build:
29+
runs-on: ubuntu-latest
30+
31+
steps:
32+
- name: Checkout code
33+
uses: actions/checkout@v3
34+
with:
35+
ref: ${{ inputs.TAG }}
36+
37+
- name: Read PHP version from composer.json (with fallback)
38+
id: php-version
39+
run: |
40+
if ! command -v "jq" &> /dev/null; then
41+
echo "PHP_VERSION=${{ inputs.PHP_VERSION }}" >> $GITHUB_ENV
42+
exit 1
43+
fi
44+
45+
# Try to extract PHP version from composer.json
46+
php_version=$(jq -r '.config.platform.php // empty' composer.json)
47+
48+
# Use a fallback version if not defined
49+
if [ -z "$php_version" ]; then
50+
php_version=${{ inputs.PHP_VERSION }}
51+
fi
52+
53+
echo "PHP_VERSION=${php_version}" >> $GITHUB_ENV
54+
55+
- name: Get Composer cache directory
56+
id: composer-cache
57+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
58+
59+
- name: Set up Composer caching
60+
uses: actions/cache@v3
61+
env:
62+
cache-name: cache-composer-dependencies
63+
with:
64+
path: ${{ steps.composer-cache.outputs.dir }}
65+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
66+
restore-keys: |
67+
${{ runner.os }}-composer-
68+
69+
- name: Setup PHP environment
70+
uses: shivammathur/setup-php@v2
71+
with:
72+
php-version: ${{ env.PHP_VERSION }}
73+
coverage: none
74+
tools: composer, cs2pr
75+
76+
- name: Install Composer dependencies
77+
if: ${{ !inputs.BUILD_FOR_DEPLOY }}
78+
env:
79+
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
80+
run: |
81+
composer install --prefer-dist --no-suggest --no-progress --no-ansi --no-interaction
82+
composer run build-translations
83+
echo "vendor/bin" >> $GITHUB_PATH
84+
x
85+
- name: Install Composer dependencies for deployment
86+
if: ${{ inputs.BUILD_FOR_DEPLOY }}
87+
env:
88+
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
89+
run: |
90+
composer install --prefer-dist --no-suggest --no-progress --no-ansi --no-interaction --no-dev
91+
composer run build-translations
92+
echo "vendor/bin" >> $GITHUB_PATH
93+
94+
- name: Setup Node.js environment
95+
uses: actions/setup-node@v4
96+
with:
97+
node-version-file: 'package.json'
98+
check-latest: true
99+
cache: npm
100+
101+
- name: Install Dependencies
102+
run: npm ci
103+
104+
- name: Build assets
105+
run: npm run build
106+
107+
- name: Create code artifact archive
108+
working-directory: ./
109+
run: |
110+
touch compressed-code-artifact.tar.gz
111+
tar -czf compressed-code-artifact.tar.gz --exclude=compressed-code-artifact.tar.gz --exclude=.git .
112+
113+
- name: Upload Artifact
114+
uses: actions/upload-artifact@v4
115+
with:
116+
name: compressed-code-artifact
117+
path: compressed-code-artifact.tar.gz
118+
retention-days: 1
119+
overwrite: true
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Manually deploy to server
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
TAG:
7+
description: 'Version to deploy, can be a tag, branch, commit or empty for latest'
8+
required: false
9+
type: string
10+
default: ''
11+
PHP_VERSION:
12+
description: 'The PHP version to use'
13+
required: false
14+
type: string
15+
default: '8.2'
16+
BUILD_FOR_DEPLOY:
17+
description: 'Whether to build for deployment immediately or to keep developer tools'
18+
required: false
19+
type: boolean
20+
default: false
21+
secrets:
22+
SERVER_USERNAME:
23+
description: 'Username for the server'
24+
required: true
25+
SERVER_HOSTNAME:
26+
description: 'Hostname for the server'
27+
required: true
28+
DEPLOYMENT_PATH:
29+
description: 'Path to deploy to on the server'
30+
required: true
31+
SERVER_PRIVATE_KEY:
32+
description: 'Private key for the server'
33+
required: true
34+
SERVER_HOSTKEY:
35+
description: 'The SSH host key of the SERVER_HOSTNAME'
36+
required: true
37+
38+
jobs:
39+
code-checkout:
40+
uses: ./.github/workflows/checkout-and-build.yml
41+
with:
42+
tag: ${{ inputs.TAG }}
43+
PHP_VERSION: ${{ inputs.PHP_VERSION }}
44+
BUILD_FOR_DEPLOY: ${{ inputs.BUILD_FOR_DEPLOY }}
45+
ARTIFACT_NAME: 'compressed-code-artifact'
46+
secrets: inherit
47+
48+
deploy:
49+
uses: 'dekodeinteraktiv/github-actions/.github/workflows/deploy-to-server.yml@main'
50+
needs: [code-checkout]
51+
with:
52+
ARTIFACT_NAME: 'compressed-code-artifact'
53+
RSYNC_FILTER_FILE: './tools/github/rsync-file-filter.rules'
54+
secrets:
55+
SERVER_USERNAME: ${{ secrets.SERVER_USERNAME }}
56+
SERVER_HOSTNAME: ${{ secrets.SERVER_HOSTNAME }}
57+
DEPLOYMENT_PATH: ${{ secrets.DEPLOYMENT_PATH }}
58+
SERVER_PRIVATE_KEY: ${{ secrets.SERVER_PRIVATE_KEY }}
59+
SERVER_HOSTKEY: ${{ secrets.SERVER_HOSTKEY }}
60+
61+
cleanup:
62+
runs-on: ubuntu-latest
63+
needs: [deploy]
64+
65+
steps:
66+
# Delete artifacts after use.
67+
- uses: geekyeggo/delete-artifact@v5
68+
with:
69+
failOnError: false
70+
name: 'compressed-code-artifact'
71+
useGlob: false

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Dekode Public GitHub Actions
2+
3+
This repository contains a collection of GitHub Actions, intended to be used in other repositories. Some of them are reusable and can be called directly from a project, while others function as templates for more specific needs.
4+
5+
## Using reusable workflows
6+
7+
To use one of the reusable workflows, call it in your project using the `uses` keyword. For example; For example, to use the `deploy` workflow, add the following to your `.github/workflows/main.yml` file:
8+
9+
```yaml
10+
jobs:
11+
deploy:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout source
15+
uses: actions/checkout@v2
16+
17+
remote:
18+
uses: dekodeinteraktiv/github-actions/.github/workflows/deploy
19+
with:
20+
INPUT_VARIABLE: 'value'
21+
secrets:
22+
SECRET_NAME: 'value'
23+
```
24+
25+
Note that you can pass `secrets: inherit` to forward all secrets, but unless they fit the workflow expectations, it is better to not over-share secrets, and instead only pass the expected ones.
26+
27+
## Adding a new workflow
28+
29+
When considering adding a new workflow, please be mindful that you've considered its reusability, and that it is generic without any direct individual project tie-ins.
30+
31+
To add a new workflow, create a new file in the `.github/workflows` directory, and add the workflow to it. Make sure the workflow is set to trigger on `workflow_call`, no actions with different triggers should be added to this repository.
32+
[See the GitHub documentation on creating reusable workflows for more information](https://docs.github.com/en/actions/using-workflows/reusing-workflows#creating-a-reusable-workflow).
33+
34+
The workflow file should have a descriptive file-name, and the workflow it self should have a name to identify it when used outside of this repository.
35+
36+
## Documenting workflows
37+
38+
To maintain a clean workflow directory, each workflow should be documented with a single file in the [`./workflows` directory](workflows/), with the same file-name as the workflow for easy identification.
39+
40+
Workflow documentation should, as a bare minimum, have a quick description of what the workflow accomplishes, and a list of inputs and outputs. For more complex workflows, it is recommended to add a more detailed description of the workflow, and how to use it.

0 commit comments

Comments
 (0)