Ontwikkel een GitHub Actions Workflow voor Geautomatiseerde Branch- en Tag-Release Strategieën
description
Met deze prompt kun je een gestructureerde en efficiënte release workflow ontwerpen die automatisch reageert op specifieke branches en tags. Dit vermindert handmatige fouten, versnelt het releaseproces en zorgt voor duidelijke scheiding tussen ontwikkelings-, test- en productieomgevingen. Het is een unieke aanpak die zich richt op branch- en tag-gestuurde automatisering, iets wat nog niet in bestaande prompts wordt behandeld.
prompt
Help me een GitHub Actions workflow te ontwerpen die automatisch verschillende CI/CD processen activeert op basis van specifieke branch- of tag-releases. Branch type: <voer het type branch in, bijvoorbeeld 'feature', 'release', 'hotfix'>. Tag naam patroon: <voer ...
try_prompt
generate_helper
disclaimerOnPageApi
tags
ai_answers
provider: openai
model: gpt-4.1-nano
Hier is een voorbeeld van een GitHub Actions workflow die automatisch CI/CD-processen activeert op basis van een specifieke branch- of tag-releases, zoals door jou beschreven:
- Branches met de naam `feature/*`
- Tags die voldoen aan het patroon `v*.*.*`
De workflow voert build, test en deploy uit afhankelijk van de trigger.
```yaml
name: CI/CD Workflow
on:
push:
branches:
- 'feature/*'
tags:
- 'v*.*.*'
jobs:
build_test_deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# Stap 1: Build
- name: Build project
run: |
echo "Building the project..."
# Voeg hier je build-commando toe, bijvoorbeeld:
# npm run build
# Stap 2: Test
- name: Run tests
run: |
echo "Running tests..."
npm test
# Stap 3: Deploy (alleen bij tags, bijvoorbeeld)
- name: Deploy
if: startsWith(github.ref, 'refs/tags/v')
run: |
echo "Deploying the release..."
# Voeg hier je deploy-commando toe
```
**Uitleg:**
- De workflow wordt geactiveerd door pushes naar branches die beginnen met `feature/` en door tags die overeenkomen met het patroon `v*.*.*`.
- De jobs voeren build, test en indien van toepassing, deploy uit.
- De stap `Deploy` wordt alleen uitgevoerd als de ref een tag is die begint met `v`, volgens jouw patroon.
Wil je dat de deploy ook automatisch gebeurt bij feature branches of alleen bij tags? Zo ja, dan kun je de `if`-voorwaarde aanpassen.
Als je nog verdere customisaties wenst, laat het gerust weten!
provider: deepseek
model: deepseek-chat
Hier is een aangepaste GitHub Actions workflow die automatisch verschillende CI/CD processen activeert op basis van branch-type en tag-releases:
```yaml
name: CI/CD Pipeline
on:
push:
branches:
- 'feature/**'
- main
tags:
- 'v*.*.*'
jobs:
build:
runs-on: ubuntu-latest
if: contains(github.ref, 'refs/heads/feature/') || contains(github.ref, 'refs/heads/main') || startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build project
run: npm run build
test:
runs-on: ubuntu-latest
needs: build
if: contains(github.ref, 'refs/heads/feature/') || contains(github.ref, 'refs/heads/main') || startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
deploy-feature:
runs-on: ubuntu-latest
needs: test
if: contains(github.ref, 'refs/heads/feature/')
steps:
- name: Deploy to feature environment
run: echo "Implementeer hier je feature deployment logica"
deploy-main:
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/main'
steps:
- name: Deploy to staging
run: echo "Implementeer hier je staging deployment logica"
deploy-release:
runs-on: ubuntu-latest
needs: test
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Deploy to production
run: echo "Implementeer hier je production deployment logica"
```
**Werking van deze workflow:**
1. **Triggers:**
- Feature branches: `feature/**`
- Main branch: `main`
- Release tags: `v*.*.*` (bijv. v1.2.3)
2. **Jobs structuur:**
- **Build:** Bouwt het project voor alle triggers
- **Test:** Voert tests uit na succesvolle build
- **Deploy:** Verschillende deploy jobs gebaseerd op branch/tag
3. **Specifieke acties per trigger:**
- **Feature branches:** Build → Test → Feature deployment
- **Main branch:** Build → Test → Staging deployment
- **Release tags:** Build → Test → Production deployment
**Belangrijke aanpassingen:**
- Gebruik van nieuwere versies van actions (`@v4`)
- Toegevoegde Node.js setup voor betere caching
- `npm ci` voor betrouwbaardere dependency installatie
- Conditionele uitvoering met `if` statements
- Gescheiden deploy jobs voor verschillende omgevingen
Pas de deployment stappen aan naar jouw specifieke implementatie (Docker, serverless, etc.).