slogan3

Optimaliseer mijn GitHub Actions workflow met geavanceerde triggers

description

Met deze prompt kan ik mijn GitHub Actions workflows verfijnen door gebruik te maken van krachtige triggeropties die niet standaard zijn, waardoor ik mijn build- en deploymentprocessen efficiënter en flexibeler kan maken dan met basistriggers. Dit lost problemen op zoals onnodige runs en maakt het mogelijk om workflows beter af te stemmen op specifieke ontwikkelingsbehoeften.

prompt

Help me een GitHub Actions workflow te ontwerpen die geavanceerde triggers gebruikt zoals schema's, pull re ...

try_prompt

generate_helper
disclaimerOnPageApi

ai_answers

provider: openai
model: gpt-4.1-nano
Hier is een voorbeeld van een geavanceerde GitHub Actions workflow die gebruikmaakt van schema-triggers, pull request labels en externe API calls: ```yaml name: Geavanceerde CI Workflow on: push: branches: - main pull_request: types: [labeled, unlabeled, opened, synchronize] schedule: - cron: '0 0 * * *' # Dagelijks om middernacht jobs: build: runs-on: ubuntu-latest if: github.event_name != 'pull_request' || github.event.pull_request.merged == false steps: - uses: actions/checkout@v2 # Stap om labels te controleren op PR's - name: Controleer PR-labels if: github.event_name == 'pull_request' run: | echo "Labels op PR:" curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels # Voorbeeld: trigger alleen bij label 'build' if curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels | grep -q 'build'; then echo "Label 'build' gevonden, gaan door." else echo "Label 'build' niet gevonden, workflow wordt afgebroken." exit 0 fi # Externe API call (bijvoorbeeld om build status te controleren) - name: Externe API call run: | RESPONSE=$(curl -s -X GET "https://api.example.com/status") echo "API Response: $RESPONSE" # Controleer de response if [[ "$RESPONSE" != *"ready"* ]]; then echo "API status niet ready, workflow wordt afgebroken." exit 0 fi - name: Installatie afhankelijkheden run: npm install - name: Test run: npm test ``` **Wat doet deze workflow?** - Triggert op push naar main, PR's met specifieke label-veranderingen, en een dagelijks schema. - Controleert PR-labels via de GitHub API. - Voert een externe API-call uit om de status te controleren voordat verder wordt gegaan. - Alleen door te gaan als de juiste labels aanwezig zijn en de API-status geschikt is. Wil je nog meer geavanceerde triggers of functies toevoegen?
provider: deepseek
model: deepseek-chat
Hier is een geavanceerde GitHub Actions workflow met de gevraagde triggers: ```yaml name: Geavanceerde CI/CD Workflow on: # Standaard push trigger push: branches: [ main, develop ] paths-ignore: - 'docs/**' - '**.md' # Scheduled trigger (elke dag om 8:00 UTC) schedule: - cron: '0 8 * * *' # Pull request triggers met labels pull_request: types: [opened, synchronize, reopened, labeled, unlabeled] branches: [ main ] # Handmatige trigger vanuit UI workflow_dispatch: inputs: environment: description: 'Omgeving om naar te deployen' required: true default: 'staging' type: choice options: - staging - production force_deploy: description: 'Forceer deploy zelfs als tests falen' required: false type: boolean # Externe repository event (bijv. van andere repo in organisatie) repository_dispatch: types: [deployment_request] jobs: # Voorwaardelijke build job build: runs-on: ubuntu-latest # Alleen uitvoeren bij push of scheduled events if: github.event_name == 'push' || github.event_name == 'schedule' steps: - uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v3 with: node-version: '18' cache: 'npm' - name: Install dependencies run: npm ci - name: Run tests run: npm test - name: Upload test results uses: actions/upload-artifact@v3 if: always() with: name: test-results path: test-results/ # PR label-gebaseerde job pr-label-check: runs-on: ubuntu-latest # Alleen bij PR events met specifieke labels if: | github.event_name == 'pull_request' && (contains(github.event.pull_request.labels.*.name, 'ready-for-review') || contains(github.event.pull_request.labels.*.name, 'hotfix')) steps: - uses: actions/checkout@v4 - name: Check PR labels run: | echo "PR gelabeld met: ${{ toJSON(github.event.pull_request.labels) }}" echo "Extra checks voor gelabelde PR..." # Externe API call job external-api-trigger: runs-on: ubuntu-latest # Alleen bij repository_dispatch events if: github.event_name == 'repository_dispatch' steps: - name: Call external API uses: fjogeleit/http-request-action@v1 with: url: 'https://api.example.com/deploy' method: 'POST' customHeaders: '{"Authorization": "Bearer ${{ secrets.API_TOKEN }}", "Content-Type": "application/json"}' data: '{"repository": "${{ github.repository }}", "ref": "${{ github.ref }}"}' # Geavanceerde conditional deployment deploy: runs-on: ubuntu-latest needs: [build, pr-label-check] # Complexe voorwaarden voor deployment if: | (github.event_name == 'workflow_dispatch' && github.event.inputs.force_deploy == true) || (github.event_name == 'push' && github.ref == 'refs/heads/main' && needs.build.result == 'success') || (github.event_name == 'repository_dispatch' && github.event.client_payload.deploy_to == 'production') environment: name: ${{ github.event.inputs.environment || 'staging' }} url: https://github.com/${{ github.repository }} steps: - name: Deploy to environment run: | echo "Deploying to ${{ github.event.inputs.environment || 'staging' }}" # Voeg je deploy script toe hier # Scheduled cleanup job cleanup: runs-on: ubuntu-latest # Alleen bij scheduled events if: github.event_name == 'schedule' steps: - name: Cleanup old artifacts uses: actions/checkout@v4 - name: Run cleanup script run: npm run cleanup ``` **Belangrijke features in deze workflow:** 1. **Schedule trigger**: Dagelijkse runs om 8:00 UTC 2. **PR label filtering**: Alleen runs bij specifieke labels ('ready-for-review', 'hotfix') 3. **Externe API calls**: HTTP requests naar externe services 4. **Workflow dispatch**: Handmatige triggers met custom inputs 5. **Repository dispatch**: Events van andere repositories 6. **Geavanceerde voorwaarden**: Complexe if-statements voor job execution 7. **Environment deployment**: Geconditioneerde deployment naar verschillende omgevingen **Benodigde secrets:** - `API_TOKEN` voor externe API authenticatie **Installatie tips:** 1. Voeg secrets toe in GitHub Repository Settings → Secrets 2. Pas API URLs en endpoints aan naar jouw services 3. Configureer environment protections indien nodig 4. Test triggers stap voor stap Deze workflow biedt een robuuste basis voor geavanceerde CI/CD scenarios met flexibele trigger voorwaarden!