Skip to content

Commit 5e8a91c

Browse files
authored
feat: first time setup, fixes #65, fixes #40 (#75)
1 parent 0bc6d90 commit 5e8a91c

File tree

6 files changed

+212
-24
lines changed

6 files changed

+212
-24
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
## The Issue
22

3-
- #<issue number>
3+
- Fixes #REPLACE_ME_WITH_RELATED_ISSUE_NUMBER
44

55
<!-- Provide a brief description of the issue. -->
66

77
## How This PR Solves The Issue
88

9+
<!-- Describe the key change(s) in this PR that address the issue above. -->
10+
911
## Manual Testing Instructions
1012

13+
<!-- If this PR changes logic, consider adding additional steps or context to the instructions below. -->
14+
1115
```bash
12-
ddev add-on get https://github.com/<user>/<repo>/tarball/<branch>
16+
ddev add-on get https://github.com/ddev/ddev-addon-template/tarball/refs/pull/REPLACE_ME_WITH_THIS_PR_NUMBER/head
1317
ddev restart
1418
```
1519

.github/scripts/first-time-setup.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
7+
GITHUB_REPOSITORY=${1?Error: Please pass repo org/name, e.g. ddev/ddev-addon-name}
8+
9+
# Extract variables
10+
FULL_REPO_NAME="$GITHUB_REPOSITORY"
11+
REPO_NAME="${GITHUB_REPOSITORY##*/}"
12+
USER_NAME="${GITHUB_REPOSITORY%%/*}"
13+
REPLACE_UNDERSCORES=${REPO_NAME//_/-}
14+
NO_PREFIX_NAME="${REPLACE_UNDERSCORES#ddev-}"
15+
LOWERCASE_NAME="${NO_PREFIX_NAME,,}"
16+
ENV_VAR_NAME=$(echo "${LOWERCASE_NAME//-/_}_DOCKER_IMAGE" | tr '[:lower:]' '[:upper:]')
17+
PRETTY_NAME=$(echo "$LOWERCASE_NAME" | sed 's/-/ /g' | awk '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) substr($i,2)} 1')
18+
19+
update_readme() {
20+
mv README_ADDON.md README.md
21+
22+
sed -i "s|ddev/ddev-addon-template|$FULL_REPO_NAME|g" README.md
23+
sed -i "s|addon-template|$LOWERCASE_NAME|g" README.md
24+
sed -i "s|Add-on Template|$PRETTY_NAME|g" README.md
25+
sed -i "s|ADDON_TEMPLATE_DOCKER_IMAGE|$ENV_VAR_NAME|g" README.md
26+
sed -i "s|@CONTRIBUTOR|\[@$USER_NAME\](https://github.com/$USER_NAME)|g" README.md
27+
}
28+
29+
update_docker_compose() {
30+
local old_file="docker-compose.addon-template.yaml"
31+
local new_file="docker-compose.$LOWERCASE_NAME.yaml"
32+
mv "$old_file" "$new_file"
33+
34+
sed -i "s|addon-template|$LOWERCASE_NAME|g" "$new_file"
35+
sed -i "s|ADDON_TEMPLATE_DOCKER_IMAGE|$ENV_VAR_NAME|g" "$new_file"
36+
}
37+
38+
update_tests_and_templates() {
39+
sed -i "s|ddev/ddev-addon-template|$FULL_REPO_NAME|g" tests/test.bats
40+
sed -i "s|ddev/ddev-addon-template|$FULL_REPO_NAME|g" .github/PULL_REQUEST_TEMPLATE.md
41+
}
42+
43+
update_license() {
44+
sed -i "s|Copyright \[yyyy\]|Copyright $(date +'%Y')|g" LICENSE
45+
}
46+
47+
create_install_yaml() {
48+
cat <<EOF > install.yaml
49+
name: $LOWERCASE_NAME
50+
51+
project_files:
52+
- docker-compose.$LOWERCASE_NAME.yaml
53+
54+
ddev_version_constraint: '>= v1.24.3'
55+
EOF
56+
}
57+
58+
cleanup_files() {
59+
rm -f README_DEBUG.md
60+
rm -f .github/workflows/first-time-setup.yml
61+
rm -rf images
62+
rm -rf .github/scripts
63+
}
64+
65+
main() {
66+
update_readme
67+
update_docker_compose
68+
update_tests_and_templates
69+
update_license
70+
create_install_yaml
71+
cleanup_files
72+
}
73+
74+
main
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: first-time-setup
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
# Only keep latest run of this workflow and cancel any previous runs
8+
concurrency:
9+
group: first-time-setup
10+
cancel-in-progress: true
11+
12+
permissions:
13+
contents: write
14+
15+
jobs:
16+
first-time-setup:
17+
if: ${{ !github.event.repository.is_template }}
18+
19+
runs-on: "ubuntu-latest"
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
25+
- name: Update files
26+
run: ./.github/scripts/first-time-setup.sh "$GITHUB_REPOSITORY"
27+
28+
- name: Commit and push changes
29+
run: |
30+
git config --global user.name "github-actions[bot]"
31+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
32+
git add .
33+
git commit -m "First time setup"
34+
git push

README.md

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
[![last commit](https://img.shields.io/github/last-commit/ddev/ddev-addon-template)](https://github.com/ddev/ddev-addon-template/commits)
44
[![release](https://img.shields.io/github/v/release/ddev/ddev-addon-template)](https://github.com/ddev/ddev-addon-template/releases/latest)
55

6-
# DDEV add-on template <!-- omit in toc -->
6+
# DDEV Add-on Template <!-- omit in toc -->
77

8-
* [What is DDEV add-on template?](#what-is-ddev-add-on-template)
8+
* [What is DDEV Add-on Template?](#what-is-ddev-add-on-template)
9+
* [TL;DR](#tldr)
910
* [Components of the repository](#components-of-the-repository)
1011
* [Getting started](#getting-started)
11-
* [How to debug in Github Actions](./README_DEBUG.md)
12+
* [How to debug in Github Actions](#how-to-debug-in-github-actions)
13+
* [Resources](#resources)
14+
* [Credits](#credits)
1215

13-
## What is DDEV add-on template?
16+
## What is DDEV Add-on Template?
1417

1518
This repository is a template for providing [DDEV](https://ddev.readthedocs.io) add-ons and services.
1619

@@ -20,6 +23,23 @@ This repository is a quick way to get started. You can create a new repo from th
2023

2124
![template button](images/template-button.png)
2225

26+
## TL;DR
27+
28+
1. Click the green `Use this template button` (top right) > `Create a new repository`.
29+
2. Name your repository using the `ddev-` prefix (e.g. `ddev-foobar`).
30+
3. Add a meaningful description with relevant keywords for discoverability.
31+
4. Click `Create repository` and wait for the automated `First time setup` commit.
32+
33+
> [!NOTE]
34+
> Automated updates to the `README.md` happen in a minute or so after creation.
35+
36+
5. Clone your repository locally (use the green `<> Code` button for the URL).
37+
6. Prepare your add-on files and tests, see [Getting started](#getting-started) for details.
38+
7. Create a new PR for review and discussion (avoid committing directly to `main`, as that bypasses the collaborative process).
39+
8. Merge or squash your PR into `main` (squash is preferred for a cleaner commit history).
40+
9. Create a new [release](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository).
41+
10. When ready to share, make your add-on discoverable by adding the `ddev-get` [topic](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/classifying-your-repository-with-topics).
42+
2343
## Components of the repository
2444

2545
* The fundamental contents of the add-on service or other component. For example, in this template there is a [docker-compose.addon-template.yaml](docker-compose.addon-template.yaml) file.
@@ -31,27 +51,35 @@ This repository is a quick way to get started. You can create a new repo from th
3151

3252
1. Choose a good descriptive name for your add-on. It should probably start with "ddev-" and include the basic service or functionality. If it's particular to a specific CMS, perhaps `ddev-<CMS>-servicename`.
3353
2. Create the new template repository by using the template button.
34-
3. Globally replace "addon-template" with the name of your add-on.
35-
4. Add the files that need to be added to a DDEV project to the repository. For example, you might replace `docker-compose.addon-template.yaml` with the `docker-compose.*.yaml` for your recipe.
36-
5. Update the `install.yaml` to give the necessary instructions for installing the add-on:
54+
3. Add the files that need to be added to a DDEV project to the repository. If your add-on does not add a new service, remove `docker-compose.<addon-name>.yaml` file.
55+
4. Update the `install.yaml` to give the necessary instructions for installing the add-on:
3756

3857
* The fundamental line is the `project_files` directive, a list of files to be copied from this repo into the project `.ddev` directory.
3958
* You can optionally add files to the `global_files` directive as well, which will cause files to be placed in the global `.ddev` directory, `~/.ddev`.
4059
* Finally, `pre_install_commands` and `post_install_commands` are supported. These can use the host-side environment variables documented [in DDEV docs](https://ddev.readthedocs.io/en/stable/users/extend/custom-commands/#environment-variables-provided).
4160

42-
6. Update `tests/test.bats` to provide a reasonable test for your repository. Tests will run automatically on every push to the repository, and periodically each night. Please make sure to address test failures when they happen. Others will be depending on you. Bats is a testing framework that just uses Bash. To run a Bats test locally, you have to install [bats-core](https://bats-core.readthedocs.io/en/stable/installation.html) and its [libraries](https://github.com/ztombol/bats-docs) first. Then you download your add-on, and finally run `bats ./tests/test.bats` within the root of the uncompressed directory. To learn more about Bats see the [documentation](https://bats-core.readthedocs.io/en/stable/).
43-
7. When everything is working, including the tests, you can push the repository to GitHub.
44-
8. Create a [release](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository) on GitHub.
45-
9. Test manually with `ddev add-on get <owner/repo>`.
46-
10. You can test PRs with `ddev add-on get https://github.com/<user>/<repo>/tarball/<branch>`.
47-
11. You can test add-ons locally without GitHub by downloading them, making changes and running `ddev add-on get /path/to/add-on-directory`.
48-
12. Update the `README.md` header, adding the machine name of the add-on, for example `# ddev-redis`, not `# DDEV Redis`.
49-
13. Update the `README.md` to describe the add-on, how to use it, and how to contribute. If there are any manual actions that have to be taken, please explain them. If it requires special configuration of the using project, please explain how to do those. Examples in [ddev/ddev-solr](https://github.com/ddev/ddev-solr), [ddev/ddev-memcached](https://github.com/ddev/ddev-memcached), and (advanced) [ddev-platformsh](https://github.com/ddev/ddev-platformsh).
50-
14. Add a good short description to your repo, and add the [topic](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/classifying-your-repository-with-topics) "ddev-get". It will immediately be added to the list provided by `ddev add-on list --all`.
51-
15. When it has matured you will hopefully want to have it become an "official" maintained add-on. Open an issue in the [DDEV queue](https://github.com/ddev/ddev/issues) for that.
61+
5. Update `tests/test.bats` to provide a reasonable test for your repository. In most cases, you only need to modify the `health_checks()` function. Tests will run automatically on every push to the repository, and periodically each night. Please make sure to address test failures when they happen. Others will be depending on you. Bats is a testing framework that just uses Bash. To run a Bats test locally, you have to install [bats-core](https://bats-core.readthedocs.io/en/stable/installation.html) and its [libraries](https://github.com/ztombol/bats-docs) first. Then you download your add-on, and finally run `bats ./tests/test.bats` within the root of the uncompressed directory. To learn more about Bats see the [documentation](https://bats-core.readthedocs.io/en/stable/).
62+
6. When everything is working, including the tests, you can push the repository to GitHub.
63+
7. Create a [release](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository) on GitHub.
64+
8. Test manually with `ddev add-on get <owner/repo>`.
65+
9. You can test PRs with `ddev add-on get https://github.com/<user>/<repo>/tarball/<branch>` or `https://github.com/<user>/<repo>/tarball/refs/pull/<pr-number>/head`.
66+
10. You can test add-ons locally without GitHub by downloading them, making changes and running `ddev add-on get /path/to/add-on-directory`.
67+
11. Update the [`README.md`](./README_ADDON.md) to describe the add-on, how to use it, and how to contribute. If there are any manual actions that have to be taken, please explain them. If it requires special configuration of the using project, please explain how to do those. Examples in [ddev/ddev-solr](https://github.com/ddev/ddev-solr), [ddev/ddev-memcached](https://github.com/ddev/ddev-memcached), and (advanced) [ddev-platformsh](https://github.com/ddev/ddev-platformsh).
68+
12. Add a good short description to your repo, and add the `ddev-get` [topic](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/classifying-your-repository-with-topics). It will immediately be added to the list provided by `ddev add-on list --all`.
69+
13. When it has matured you will hopefully want to have it become an "official" maintained add-on. Open an issue in the [DDEV queue](https://github.com/ddev/ddev/issues) for that.
70+
71+
## How to debug in Github Actions
72+
73+
See [full instructions](./README_DEBUG.md).
74+
75+
## Resources
5276

53-
Add-ons were covered in [DDEV Add-ons: Creating, maintaining, testing](https://www.youtube.com/watch?v=TmXqQe48iqE) (part of the [DDEV Contributor Live Training](https://ddev.com/blog/contributor-training)).
77+
* [DDEV Add-ons: Creating, maintaining, testing](https://www.youtube.com/watch?v=TmXqQe48iqE) (part of the [DDEV Contributor Live Training](https://ddev.com/blog/contributor-training))
78+
* [Advanced Add-On Techniques](https://ddev.com/blog/advanced-add-on-contributor-training/)
79+
* [DDEV Add-on Maintenance Guide](https://ddev.com/blog/ddev-add-on-maintenance-guide/)
80+
* [DDEV docs](https://ddev.readthedocs.io/en/stable/users/extend/additional-services/)
81+
* [DDEV Add-on Registry](https://addons.ddev.com/)
5482

55-
Note that more advanced techniques are discussed in [Advanced Add-On Techniques](https://ddev.com/blog/advanced-add-on-contributor-training/) and [DDEV docs](https://ddev.readthedocs.io/en/stable/users/extend/additional-services/).
83+
## Credits
5684

57-
**Contributed and maintained by `@CONTRIBUTOR`**
85+
**Contributed and maintained by @CONTRIBUTOR**

README_ADDON.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
[![add-on registry](https://img.shields.io/badge/DDEV-Add--on_Registry-blue)](https://addons.ddev.com)
2+
[![tests](https://github.com/ddev/ddev-addon-template/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/ddev/ddev-addon-template/actions/workflows/tests.yml?query=branch%3Amain)
3+
[![last commit](https://img.shields.io/github/last-commit/ddev/ddev-addon-template)](https://github.com/ddev/ddev-addon-template/commits)
4+
[![release](https://img.shields.io/github/v/release/ddev/ddev-addon-template)](https://github.com/ddev/ddev-addon-template/releases/latest)
5+
6+
# DDEV Add-on Template
7+
8+
## Overview
9+
10+
This add-on integrates Add-on Template into your [DDEV](https://ddev.com/) project.
11+
12+
## Installation
13+
14+
```bash
15+
ddev add-on get ddev/ddev-addon-template
16+
ddev restart
17+
```
18+
19+
After installation, make sure to commit the `.ddev` directory to version control.
20+
21+
## Usage
22+
23+
| Command | Description |
24+
| ------- | ----------- |
25+
| `ddev describe` | View service status and used ports for Add-on Template |
26+
| `ddev logs -s addon-template` | Check Add-on Template logs |
27+
28+
## Advanced Customization
29+
30+
To change the Docker image:
31+
32+
```bash
33+
ddev dotenv set .ddev/.env.addon-template --addon-template-docker-image="busybox:stable"
34+
ddev add-on get ddev/ddev-addon-template
35+
ddev restart
36+
```
37+
38+
Make sure to commit the `.ddev/.env.addon-template` file to version control.
39+
40+
All customization options (use with caution):
41+
42+
| Variable | Flag | Default |
43+
| -------- | ---- | ------- |
44+
| `ADDON_TEMPLATE_DOCKER_IMAGE` | `--addon-template-docker-image` | `busybox:stable` |
45+
46+
## Credits
47+
48+
**Contributed and maintained by @CONTRIBUTOR**

docker-compose.addon-template.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
services:
44
addon-template:
55
container_name: ddev-${DDEV_SITENAME}-addon-template
6-
image: busybox:stable
6+
image: ${ADDON_TEMPLATE_DOCKER_IMAGE:-busybox:stable}
77
command: tail -f /dev/null
88
restart: "no"
99
# These labels ensure this service is discoverable by DDEV.
1010
labels:
1111
com.ddev.site-name: ${DDEV_SITENAME}
12-
com.ddev.approot: $DDEV_APPROOT
12+
com.ddev.approot: ${DDEV_APPROOT}
1313

1414
volumes:
1515
- ".:/mnt/ddev_config"

0 commit comments

Comments
 (0)