$npx -y skills add wshobson/agents --skill github-actions-templatesCreate production-ready GitHub Actions workflows for automated testing, building, and deploying applications. Use when setting up CI/CD with GitHub Actions, automating development workflows, or creating reusable workflow templates.
| 1 | # GitHub Actions Templates |
| 2 | |
| 3 | Production-ready GitHub Actions workflow patterns for testing, building, and deploying applications. |
| 4 | |
| 5 | ## Purpose |
| 6 | |
| 7 | Create efficient, secure GitHub Actions workflows for continuous integration and deployment across various tech stacks. |
| 8 | |
| 9 | ## When to Use |
| 10 | |
| 11 | - Automate testing and deployment |
| 12 | - Build Docker images and push to registries |
| 13 | - Deploy to Kubernetes clusters |
| 14 | - Run security scans |
| 15 | - Implement matrix builds for multiple environments |
| 16 | |
| 17 | ## Common Workflow Patterns |
| 18 | |
| 19 | ### Pattern 1: Test Workflow |
| 20 | |
| 21 | ```yaml |
| 22 | name: Test |
| 23 | |
| 24 | on: |
| 25 | push: |
| 26 | branches: [main, develop] |
| 27 | pull_request: |
| 28 | branches: [main] |
| 29 | |
| 30 | jobs: |
| 31 | test: |
| 32 | runs-on: ubuntu-latest |
| 33 | |
| 34 | strategy: |
| 35 | matrix: |
| 36 | node-version: [18.x, 20.x] |
| 37 | |
| 38 | steps: |
| 39 | - uses: actions/checkout@v4 |
| 40 | |
| 41 | - name: Use Node.js ${{ matrix.node-version }} |
| 42 | uses: actions/setup-node@v4 |
| 43 | with: |
| 44 | node-version: ${{ matrix.node-version }} |
| 45 | cache: "npm" |
| 46 | |
| 47 | - name: Install dependencies |
| 48 | run: npm ci |
| 49 | |
| 50 | - name: Run linter |
| 51 | run: npm run lint |
| 52 | |
| 53 | - name: Run tests |
| 54 | run: npm test |
| 55 | |
| 56 | - name: Upload coverage |
| 57 | uses: codecov/codecov-action@v4 |
| 58 | with: |
| 59 | files: ./coverage/lcov.info |
| 60 | ``` |
| 61 | |
| 62 | **Reference:** See `assets/test-workflow.yml` |
| 63 | |
| 64 | ### Pattern 2: Build and Push Docker Image |
| 65 | |
| 66 | ```yaml |
| 67 | name: Build and Push |
| 68 | |
| 69 | on: |
| 70 | push: |
| 71 | branches: [main] |
| 72 | tags: ["v*"] |
| 73 | |
| 74 | env: |
| 75 | REGISTRY: ghcr.io |
| 76 | IMAGE_NAME: ${{ github.repository }} |
| 77 | |
| 78 | jobs: |
| 79 | build: |
| 80 | runs-on: ubuntu-latest |
| 81 | permissions: |
| 82 | contents: read |
| 83 | packages: write |
| 84 | |
| 85 | steps: |
| 86 | - uses: actions/checkout@v4 |
| 87 | |
| 88 | - name: Log in to Container Registry |
| 89 | uses: docker/login-action@v3 |
| 90 | with: |
| 91 | registry: ${{ env.REGISTRY }} |
| 92 | username: ${{ github.actor }} |
| 93 | password: ${{ secrets.GITHUB_TOKEN }} |
| 94 | |
| 95 | - name: Extract metadata |
| 96 | id: meta |
| 97 | uses: docker/metadata-action@v5 |
| 98 | with: |
| 99 | images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 100 | tags: | |
| 101 | type=ref,event=branch |
| 102 | type=ref,event=pr |
| 103 | type=semver,pattern={{version}} |
| 104 | type=semver,pattern={{major}}.{{minor}} |
| 105 | |
| 106 | - name: Build and push |
| 107 | uses: docker/build-push-action@v5 |
| 108 | with: |
| 109 | context: . |
| 110 | push: true |
| 111 | tags: ${{ steps.meta.outputs.tags }} |
| 112 | labels: ${{ steps.meta.outputs.labels }} |
| 113 | cache-from: type=gha |
| 114 | cache-to: type=gha,mode=max |
| 115 | ``` |
| 116 | |
| 117 | **Reference:** See `assets/deploy-workflow.yml` |
| 118 | |
| 119 | ### Pattern 3: Deploy to Kubernetes |
| 120 | |
| 121 | ```yaml |
| 122 | name: Deploy to Kubernetes |
| 123 | |
| 124 | on: |
| 125 | push: |
| 126 | branches: [main] |
| 127 | |
| 128 | jobs: |
| 129 | deploy: |
| 130 | runs-on: ubuntu-latest |
| 131 | |
| 132 | steps: |
| 133 | - uses: actions/checkout@v4 |
| 134 | |
| 135 | - name: Configure AWS credentials |
| 136 | uses: aws-actions/configure-aws-credentials@v4 |
| 137 | with: |
| 138 | aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 139 | aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 140 | aws-region: us-west-2 |
| 141 | |
| 142 | - name: Update kubeconfig |
| 143 | run: | |
| 144 | aws eks update-kubeconfig --name production-cluster --region us-west-2 |
| 145 | |
| 146 | - name: Deploy to Kubernetes |
| 147 | run: | |
| 148 | kubectl apply -f k8s/ |
| 149 | kubectl rollout status deployment/my-app -n production |
| 150 | kubectl get services -n production |
| 151 | |
| 152 | - name: Verify deployment |
| 153 | run: | |
| 154 | kubectl get pods -n production |
| 155 | kubectl describe deployment my-app -n production |
| 156 | ``` |
| 157 | |
| 158 | ### Pattern 4: Matrix Build |
| 159 | |
| 160 | ```yaml |
| 161 | name: Matrix Build |
| 162 | |
| 163 | on: [push, pull_request] |
| 164 | |
| 165 | jobs: |
| 166 | build: |
| 167 | runs-on: ${{ matrix.os }} |
| 168 | |
| 169 | strategy: |
| 170 | matrix: |
| 171 | os: [ubuntu-latest, macos-latest, windows-latest] |
| 172 | python-version: ["3.9", "3.10", "3.11", "3.12"] |
| 173 | |
| 174 | steps: |
| 175 | - uses: actions/checkout@v4 |
| 176 | |
| 177 | - name: Set up Python |
| 178 | uses: actions/setup-python@v5 |
| 179 | with: |
| 180 | python-version: ${{ matrix.python-version }} |
| 181 | |
| 182 | - name: Install dependencies |
| 183 | run: | |
| 184 | python -m pip install --upgrade pip |
| 185 | pip install -r requirements.txt |
| 186 | |
| 187 | - name: Run tests |
| 188 | run: pytest |
| 189 | ``` |
| 190 | |
| 191 | **Reference:** See `assets/matrix-build.yml` |
| 192 | |
| 193 | ## Workflow Best Practices |
| 194 | |
| 195 | 1. **Use specific action versions** (@v4, not @latest) |
| 196 | 2. **Cache dependencies** to speed up builds |
| 197 | 3. **Use secrets** for sensitive data |
| 198 | 4. **Implement status checks** on PRs |
| 199 | 5. **Use matrix builds** for multi-version testing |
| 200 | 6. **Set appropriate permissions** |
| 201 | 7. **Use reusable workflows** for common patterns |
| 202 | 8. **Implement approval gates** for production |
| 203 | 9. **Add notification steps** for failures |
| 204 | 10. **Use self-hosted runners** for sensitive workloads |
| 205 | |
| 206 | ## Reusable Workflows |
| 207 | |
| 208 | ```yaml |
| 209 | # .github/workflows/reusable-te |