Skip to content

Commit 59edcea

Browse files
authored
Habakke/enhance actions (#41)
1 parent 9ffc374 commit 59edcea

16 files changed

Lines changed: 729 additions & 249 deletions

File tree

.github/actions/auth-github/action.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

.github/actions/docker-security-scan/action.yml

Lines changed: 0 additions & 42 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ on:
1111
required: false
1212
default: false
1313

14+
permissions:
15+
1416
jobs:
1517
release:
1618
runs-on: ubuntu-latest
@@ -21,8 +23,21 @@ jobs:
2123
steps:
2224
- name: Checkout
2325
uses: actions/checkout@v4
24-
- uses: ./.github/actions/release
26+
27+
- name: Create release
28+
id: create-release
29+
uses: ./release-action
2530
with:
2631
version: ${{ inputs.version }}
2732
pre_release: ${{ inputs.pre_release }}
2833
github_token: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Generate job summary
36+
shell: bash
37+
run: |
38+
echo "## Release Created Successfully" >> $GITHUB_STEP_SUMMARY
39+
echo "" >> $GITHUB_STEP_SUMMARY
40+
echo "- **Version**: ${{ inputs.version }}" >> $GITHUB_STEP_SUMMARY
41+
echo "- **Pre-release**: ${{ inputs.pre_release }}" >> $GITHUB_STEP_SUMMARY
42+
echo "- **Release URL**: https://github.com/${{ github.repository }}/releases/tag/${{ inputs.version }}" >> $GITHUB_STEP_SUMMARY
43+
echo "" >> $GITHUB_STEP_SUMMARY

README.md

Lines changed: 202 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,213 @@
1-
# shared-github-actions
2-
Github-actions worflows and actions accessible to all Pexip workflows
1+
# Pexip shared github-actions
32

4-
## Examples
3+
GitHub Actions workflows and actions accessible to all Pexip workflows. This repository provides reusable composite actions for common CI/CD tasks including Docker builds, security scanning, Terraform deployments, and release automation.
4+
5+
## Table of Contents
6+
7+
- [Available Actions](#available-actions)
8+
- [Quick Start](#quick-start)
9+
- [Prerequisites](#prerequisites)
10+
- [Examples](#examples)
11+
12+
## Available Actions
13+
14+
### Authentication
15+
16+
- **[auth-gcp-action](auth-gcp-action)** - Authenticate with Google Cloud Platform using service account key or workload identity federation
17+
- **[auth-github-action](auth-github-action)** - Authenticate with GitHub Container Registry
18+
19+
### Docker
20+
21+
- **[docker-build-action](docker-build-action)** - Build and push Docker images with automatic tagging and metadata
22+
- **[docker-security-scan-action](docker-security-scan-action)** - Security scan Docker images using Snyk
23+
24+
### Terraform
25+
26+
- **[terraform-deploy-gcp-action](terraform-deploy-gcp-action)** - Deploy infrastructure to GCP using Terraform (init, validate, plan, apply)
27+
- **[terraform-deploy-openstack-action](terraform-deploy-openstack-action)** - Deploy infrastructure to OpenStack using Terraform
28+
29+
### Release
30+
31+
- **[release-action](release-action)** - Create GitHub releases with auto-generated notes and optional Jira integration
32+
33+
### Security Tools
34+
35+
- **[setup-zizmor-action](setup-zizmor-action)** - Install zizmor CLI tool for GitHub Actions security analysis
36+
37+
## Quick Start
538

6-
The examples are located in the '/examples' folder.
39+
### Using Actions in Your Workflow
740

8-
## Automatically generated release notes
41+
Reference actions from this repository using the following pattern:
942

10-
The release workflow automatically generates release notes based on how pull requests are labeled.
11-
The example configuration expects the following labels to be used:
43+
```yaml
44+
uses: pexip/shared-github-actions/{action-name}@{ref}
45+
```
46+
47+
### Example: Build and Push Docker Image
48+
49+
```yaml
50+
steps:
51+
- name: Checkout
52+
uses: actions/checkout@v4
53+
54+
- uses: pexip/shared-github-actions/auth-gcp-action@master
55+
with:
56+
repository: ${{ vars.DOCKER_REPO }}
57+
service_account_key: ${{ secrets.DEPLOY_SERVICE_ACCOUNT_KEY }}
1258

13-
* bug
14-
* change
15-
* feature
59+
- uses: pexip/shared-github-actions/docker-build-action@master
60+
with:
61+
repository: ${{ vars.DOCKER_REPO }}
62+
image_name: my-application
63+
dockerfile: Dockerfile
64+
```
1665
17-
This is controlled through the '.github/release.yml' configuration file
66+
### Example: Terraform Deployment
1867
1968
```yaml
20-
changelog:
21-
categories:
22-
- title: New
23-
labels:
24-
- '*'
25-
exclude:
26-
labels:
27-
- bug
28-
- change
29-
- title: Changes
30-
labels:
31-
- change
32-
- title: Bug Fixes
33-
labels:
34-
- bug
69+
steps:
70+
- name: Checkout
71+
uses: actions/checkout@v4
72+
73+
- uses: pexip/shared-github-actions/auth-gcp-action@master
74+
with:
75+
repository: ${{ vars.DOCKER_REPO }}
76+
service_account_key: ${{ secrets.DEPLOY_SERVICE_ACCOUNT_KEY }}
77+
78+
- uses: pexip/shared-github-actions/terraform-deploy-gcp-action@master
79+
with:
80+
directory: ./deploy
81+
token: ${{ secrets.GITHUB_TOKEN }}
3582
```
3683
84+
### Example: Authenticate with Workload Identity Federation
85+
86+
Workload Identity Federation allows GitHub Actions to authenticate to GCP without using service account keys.
87+
88+
#### Prerequisites
89+
90+
1. **Create a Workload Identity Pool:**
91+
```bash
92+
gcloud iam workload-identity-pools create "github-pool" \
93+
--project="${PROJECT_ID}" \
94+
--location="global" \
95+
--display-name="GitHub Actions Pool"
96+
```
97+
98+
2. **Create a Workload Identity Provider:**
99+
```bash
100+
gcloud iam workload-identity-pools providers create-oidc "github-provider" \
101+
--project="${PROJECT_ID}" \
102+
--location="global" \
103+
--workload-identity-pool="github-pool" \
104+
--display-name="GitHub provider" \
105+
--attribute-mapping="google.subject=assertion.sub,attribute.actor=assertion.actor,attribute.repository=assertion.repository,attribute.repository_owner=assertion.repository_owner" \
106+
--attribute-condition="assertion.repository_owner == 'pexip'" \
107+
--issuer-uri="https://token.actions.githubusercontent.com"
108+
```
109+
110+
3. **Create a Service Account:**
111+
```bash
112+
gcloud iam service-accounts create "github-actions-sa" \
113+
--project="${PROJECT_ID}" \
114+
--display-name="GitHub Actions Service Account"
115+
```
116+
117+
4. **Grant permissions to the Service Account:**
118+
```bash
119+
# Example: Grant Artifact Registry
120+
gcloud projects add-iam-policy-binding ${PROJECT_ID} \
121+
--member="serviceAccount:github-actions-sa@${PROJECT_ID}.iam.gserviceaccount.com" \
122+
--role="roles/artifactregistry.writer"
123+
```
124+
125+
5. **Allow the Workload Identity Pool to impersonate the Service Account:**
126+
```bash
127+
gcloud iam service-accounts add-iam-policy-binding "github-actions-sa@${PROJECT_ID}.iam.gserviceaccount.com" \
128+
--project="${PROJECT_ID}" \
129+
--role="roles/iam.workloadIdentityUser" \
130+
--member="principalSet://iam.googleapis.com/projects/${PROJECT_NUMBER}/locations/global/workloadIdentityPools/github-pool/attribute.repository/pexip/REPOSITORY_NAME"
131+
```
132+
133+
6. **Get the Workload Identity Provider resource name:**
134+
```bash
135+
gcloud iam workload-identity-pools providers describe "github-provider" \
136+
--project="${PROJECT_ID}" \
137+
--location="global" \
138+
--workload-identity-pool="github-pool" \
139+
--format="value(name)"
140+
```
141+
Save this value as `WORKLOAD_IDENTITY_PROVIDER` variable in your repository.
142+
143+
#### Usage
144+
145+
```yaml
146+
steps:
147+
- name: Checkout
148+
uses: actions/checkout@v4
149+
150+
- uses: pexip/shared-github-actions/auth-gcp-action@master
151+
with:
152+
repository: ${{ vars.DOCKER_REPO }}
153+
workload_identity_provider: ${{ vars.WORKLOAD_IDENTITY_PROVIDER }}
154+
service_account: ${{ vars.SERVICE_ACCOUNT_EMAIL }}
155+
156+
- uses: pexip/shared-github-actions/docker-build-action@master
157+
with:
158+
repository: ${{ vars.DOCKER_REPO }}
159+
image_name: my-application
160+
dockerfile: Dockerfile
161+
```
162+
163+
### Example: Create a Release
164+
165+
```yaml
166+
steps:
167+
- name: Checkout
168+
uses: actions/checkout@v4
169+
170+
- uses: pexip/shared-github-actions/release-action@master
171+
with:
172+
version: v1.0.0
173+
github_token: ${{ secrets.GITHUB_TOKEN }}
174+
```
175+
176+
## Prerequisites
177+
178+
### Required Secrets
179+
180+
Configure these secrets in your repository settings:
181+
182+
- **`DEPLOY_SERVICE_ACCOUNT_KEY`** - GCP service account JSON key for authentication and Docker registry access
183+
- **`SNYK_PEXIP_UNSORTED_ACCESS_TOKEN`** - Snyk API token for security scanning (if using docker-security-scan)
184+
- **`GITHUB_TOKEN`** - Automatically provided by GitHub Actions
185+
186+
### Optional Secrets
187+
188+
- **`jira_webhook`** - Jira automation webhook URL for release integration
189+
190+
### Required Variables
191+
192+
Configure these variables in your repository settings:
193+
194+
- **`DOCKER_REPO`** - Docker repository URL (e.g., `europe-docker.pkg.dev/project-id/repo-name`)
195+
- **`DOCKER_IMAGE`** - Docker image name
196+
- **`DEPLOY_PROJECT_ID`** - GCP project ID for deployments
197+
198+
### Optional Variables (for Workload Identity Federation)
199+
200+
If using Workload Identity Federation instead of service account keys:
201+
202+
- **`WORKLOAD_IDENTITY_PROVIDER`** - Workload identity provider resource name (e.g., `projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/POOL_ID/providers/PROVIDER_ID`)
203+
- **`SERVICE_ACCOUNT_EMAIL`** - Service account email to impersonate (e.g., `my-service-account@project-id.iam.gserviceaccount.com`)
204+
205+
## Examples
206+
207+
Complete workflow examples are located in the [examples](examples) folder:
208+
209+
- **[development.yml](examples/development.yml)** - Full development pipeline with Docker build, security scan, and Terraform deployment
210+
- **[production.yml](examples/production.yml)** - Production deployment workflow triggered on main branch pushes or version tags
211+
- **[release.yml](examples/release.yml)** - Release workflow with GitHub and Jira integration
37212

213+
These examples demonstrate common patterns for integrating multiple actions into complete CI/CD pipelines.

_shared/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Shared Action Modules
2+
3+
This directory contains shared JavaScript modules used by multiple composite actions to avoid code duplication.
4+
5+
## terraform-pr-comment.js
6+
7+
Shared module for posting Terraform plan results to pull request comments.
8+
9+
### Features
10+
11+
- **Single source of truth**: Eliminates code duplication across terraform-deploy-gcp and terraform-deploy-openstack
12+
- **Reliable plan reading**: Reads from terraform.plan.txt file instead of unreliable stdout
13+
- **Smart updates**: Only updates comments when content actually changes (MD5 hash comparison)
14+
- **Size management**: Automatically truncates large plans with warnings
15+
- **Security warnings**: Detects and warns about potential sensitive values
16+
- **Destroy warnings**: Highlights when resources will be destroyed
17+
- **Platform-specific branding**: Different emojis and labels for GCP vs OpenStack
18+
- **Error handling**: Graceful failures that don't break the workflow
19+
20+
### Usage
21+
22+
```javascript
23+
const prComment = require('${{ github.action_path }}/../_shared/terraform-pr-comment.js');
24+
25+
await prComment.createOrUpdatePRComment({
26+
github,
27+
context,
28+
core,
29+
directory: './terraform',
30+
platform: 'gcp', // or 'openstack'
31+
outcomes: {
32+
fmt: 'success',
33+
init: 'success',
34+
validate: 'success',
35+
trivy: 'success',
36+
plan: 'success'
37+
},
38+
validationOutput: 'Validation output here...'
39+
});
40+
```
41+
42+
### Maintenance
43+
44+
When updating this module, remember that changes will affect both:
45+
- `.github/actions/terraform-deploy-gcp/action.yml`
46+
- `.github/actions/terraform-deploy-openstack/action.yml`
47+
48+
Test changes with both platforms before committing.

0 commit comments

Comments
 (0)