Skip to content

Commit 583430c

Browse files
feat: Added spac-flow-docker-snapshot (#60)
* init workflow * added AZUREDEVOPS_PAT * added shell: bash * added check for azdo pat * removed environment * typo fix * changed variables names * changed variables names * updated tasks versions * added debug echos * added readme * fix PR title
1 parent 4a4c25c commit 583430c

File tree

3 files changed

+127
-1
lines changed

3 files changed

+127
-1
lines changed

.github/workflows/pr-title.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
requireScope: false
3232
# Configure additional validation for the subject based on a regex.
3333
# This example ensures the subject starts with an uppercase character.
34-
subjectPattern: ^[A-Z].+$
34+
subjectPattern: ^.+$
3535
# If `subjectPattern` is configured, you can use this property to override
3636
# the default error message that is shown when the pattern doesn't match.
3737
# The variables `subject` and `title` can be used within the message.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# spac-flow-docker-snapshot
2+
3+
Allows to build docker image with the follow tags:
4+
5+
- snapshot
6+
- snapshot-(branch name)
7+
8+
and if runned manually, create a fake tag called `develop-snapshot`
9+
10+
## how to use
11+
12+
```yaml
13+
name: SPAC Snapshot docker build and push
14+
15+
on:
16+
push:
17+
branches-ignore:
18+
- 'main'
19+
paths-ignore:
20+
- 'CODEOWNERS'
21+
- '**.md'
22+
- '.**'
23+
workflow_dispatch:
24+
25+
env:
26+
CURRENT_BRANCH: ${{ github.event.inputs.branch || github.ref_name }}
27+
28+
jobs:
29+
spac-flow-docker-snapshot:
30+
runs-on: ubuntu-22.04
31+
environment: dev
32+
steps:
33+
- name: 🔖 Checkout code
34+
# https://github.com/actions/checkout/releases/tag/v4.2.1
35+
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871
36+
with:
37+
ref: ${{ env.CURRENT_BRANCH }}
38+
39+
- name: 📦 Run Snapshot Docker Build/Push & Trigger
40+
uses: pagopa/github-actions-template/spac-flow-docker-snapshot@spac-flow-docker-snapshot
41+
with:
42+
current_branch: ${{ github.ref_name }}
43+
enable_azure_devops_step: 'true'
44+
azure_devops_apps: "[one-color]"
45+
azure_devops_project_url: 'https://dev.azure.com/pagopaspa/devopslab-projects'
46+
azure_devops_pipeline_name: 'devopslab-diego-deploy.deploy'
47+
azure_devops_pat: ${{ secrets.AZUREDEVOPS_PAT }}
48+
```
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: SPAC flow docker snapshot
2+
description: SPAC flow docker snapshot
3+
4+
inputs:
5+
current_branch:
6+
required: true
7+
docker_labels:
8+
required: false
9+
default: |
10+
maintainer=https://pagopa.it
11+
org.opencontainers.image.source=https://github.com/${{ github.repository }}
12+
enable_azure_devops_step:
13+
required: false
14+
default: false
15+
azure_devops_apps:
16+
required: false
17+
azure_devops_project_url:
18+
required: false
19+
azure_devops_pipeline_name:
20+
required: false
21+
azure_devops_pat:
22+
required: false
23+
default: ''
24+
25+
runs:
26+
using: "composite"
27+
steps:
28+
- name: Log in to the Github Container registry
29+
# https://github.com/docker/login-action/releases/tag/v3.3.0
30+
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
31+
with:
32+
registry: ghcr.io
33+
username: ${{ github.actor }}
34+
password: ${{ github.token }}
35+
36+
- name: Set Docker tags
37+
id: set_docker_tags
38+
shell: bash
39+
run: |
40+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
41+
echo "DOCKER_TAGS=ghcr.io/${{ github.repository }}:develop-latest,ghcr.io/${{ github.repository }}:snapshot" >> $GITHUB_OUTPUT
42+
else
43+
echo "DOCKER_TAGS=ghcr.io/${{ github.repository }}:snapshot,ghcr.io/${{ github.repository }}:snapshot-${{ inputs.current_branch }}" >> $GITHUB_OUTPUT
44+
fi
45+
46+
- name: Build and push Docker image
47+
# https://github.com/docker/build-push-action/releases/tag/v6.9.0
48+
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75
49+
with:
50+
context: .
51+
push: true
52+
tags: ${{ steps.set_docker_tags.outputs.DOCKER_TAGS }}
53+
labels: ${{ inputs.docker_labels }}
54+
55+
- name: Check azure_devops_pat
56+
if: ${{ inputs.enable_azure_devops_step == 'true' }}
57+
shell: bash
58+
run: |
59+
if [ -z "${{ inputs.azure_devops_pat }}" ]; then
60+
echo "Error: azure_devops_pat is empty. This is required for triggering the Azure DevOps pipeline."
61+
exit 1
62+
fi
63+
64+
echo "🔨 Start launch trigger with Azure Devops"
65+
66+
- name: Trigger Azure DevOps pipeline
67+
if: ${{ inputs.enable_azure_devops_step == 'true' }}
68+
uses: jacopocarlini/azure-pipelines@v1.3
69+
with:
70+
azure-devops-project-url: ${{ inputs.azure_devops_project_url }}
71+
azure-pipeline-name: ${{ inputs.azure_devops_pipeline_name }}
72+
azure-devops-token: ${{ inputs.azure_devops_pat }}
73+
azure-template-parameters: |
74+
{
75+
"APPS": "${{ inputs.azure_devops_apps }}",
76+
"POSTMAN_BRANCH": "${{ inputs.current_branch }}"
77+
}
78+
azure-pipeline-variables: '{"system.debug": "true"}'

0 commit comments

Comments
 (0)