Skip to content

Commit b56fb98

Browse files
author
Emil Matyjaszewski
committed
Add SDLC workflows
1 parent eaff0fa commit b56fb98

File tree

5 files changed

+290
-0
lines changed

5 files changed

+290
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: SDLC - Develop push
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
8+
jobs:
9+
build-push-develop:
10+
name: "Build & push image"
11+
runs-on: ubuntu-latest
12+
if: github.ref == 'refs/heads/develop'
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Docker Buildx
18+
uses: docker/setup-buildx-action@v3
19+
20+
- name: Log in to Docker Hub
21+
uses: docker/login-action@v3
22+
with:
23+
username: ${{ secrets.DOCKERHUB_USERNAME }}
24+
password: ${{ secrets.DOCKERHUB_TOKEN }}
25+
26+
- name: Build and push develop image
27+
run: |
28+
IMAGE_TAG="develop"
29+
docker buildx create --use
30+
docker buildx build \
31+
--cache-from ${{ vars.DOCKERHUB_ORGANIZATION }}/${{ var.DOCKERHUB_REPOSITORY }}:cache-$IMAGE_TAG-dist \
32+
--cache-to ${{ vars.DOCKERHUB_ORGANIZATION }}/${{ var.DOCKERHUB_REPOSITORY }}:cache-$IMAGE_TAG-dist \
33+
-t ${{ vars.DOCKERHUB_ORGANIZATION }}/${{ var.DOCKERHUB_REPOSITORY }}:$IMAGE_TAG-dist \
34+
-f ./Dockerfile \
35+
--push \
36+
./
37+
38+
deploy:
39+
name: "Trigger deployment"
40+
needs: [build-push-develop]
41+
uses: ./.github/workflows/trigger-azure-pipeline.yml
42+
with:
43+
azure-organization: ${{ vars.AZURE_ORGANIZATION }}
44+
azure-project: ${{ vars.AZURE_PROJECT }}
45+
azure-pipeline-id: 1634
46+
secrets:
47+
azure-pat: ${{ secrets.AZURE_PAT }}

.github/workflows/sdlc-stable.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: SDLC - Stable create
2+
3+
on:
4+
create:
5+
branches:
6+
- 'stable/*'
7+
8+
jobs:
9+
stable-create:
10+
name: "Prepare application version"
11+
runs-on: ubuntu-latest
12+
if: github.event_name == 'create' && startsWith(github.ref, 'refs/heads/stable/')
13+
outputs:
14+
version: ${{ steps.version.outputs.version }}
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- id: version
20+
name: Extract stable version from branch name
21+
run: |
22+
BRANCH_NAME=${GITHUB_REF#refs/heads/stable/}
23+
VERSION=$(echo $BRANCH_NAME | cut -d '.' -f1,2)
24+
echo "VERSION=$VERSION" >> $GITHUB_ENV
25+
echo "version=$VERSION" >> $GITHUB_OUTPUT
26+
27+
- name: Remove "-RC" suffix in pyproject.toml
28+
run: |
29+
git checkout $GITHUB_REF_NAME
30+
sed -i 's/-RC//' pyproject.toml
31+
git config user.name "github-actions"
32+
git config user.email "github-actions@github.com"
33+
git commit -am "Remove -RC suffix for stable release ${{ env.VERSION }}"
34+
git push origin $GITHUB_REF_NAME
35+
36+
build-push-stable:
37+
name: "Build & push image"
38+
runs-on: ubuntu-latest
39+
needs: [stable-create]
40+
steps:
41+
- name: Checkout code
42+
uses: actions/checkout@v4
43+
44+
- name: Log in to Docker Hub
45+
uses: docker/login-action@v3
46+
with:
47+
username: ${{ secrets.DOCKERHUB_USERNAME }}
48+
password: ${{ secrets.DOCKERHUB_TOKEN }}
49+
50+
- name: Retag and push stable image
51+
run: |
52+
docker pull ${{ vars.DOCKERHUB_ORGANIZATION }}/${{ var.DOCKERHUB_REPOSITORY }}:${{ needs.stable-create.outputs.version }}-RC
53+
docker tag ${{ vars.DOCKERHUB_ORGANIZATION }}/${{ var.DOCKERHUB_REPOSITORY }}:${{ needs.stable-create.outputs.version }}-RC ${{ vars.DOCKERHUB_ORGANIZATION }}/${{ var.DOCKERHUB_REPOSITORY }}:${{ env.VERSION }}
54+
docker push ${{ vars.DOCKERHUB_ORGANIZATION }}/${{ var.DOCKERHUB_REPOSITORY }}:${{ needs.stable-create.outputs.version }}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: SDLC - UAT create
2+
3+
on:
4+
create:
5+
branches:
6+
- 'uat/*'
7+
8+
jobs:
9+
version-bump-on-uat-create:
10+
name: "Bump application version"
11+
runs-on: ubuntu-latest
12+
if: github.event_name == 'create' && startsWith(github.ref, 'refs/heads/uat/')
13+
outputs:
14+
version: ${{ steps.version.outputs.version }}
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Extract version from branch name
20+
run: |
21+
BRANCH_NAME=${GITHUB_REF#refs/heads/uat/}
22+
VERSION=$(echo $BRANCH_NAME | cut -d '.' -f1,2)
23+
echo "VERSION=$VERSION" >> $GITHUB_ENV
24+
25+
- name: Bump minor version in develop
26+
run: |
27+
git remote update
28+
git fetch
29+
git checkout develop
30+
OLD_VERSION=$(grep '^version =' pyproject.toml | awk '{print $3}')
31+
MAJOR=$(echo $OLD_VERSION | cut -d. -f1)
32+
MINOR=$(echo $OLD_VERSION | cut -d. -f2)
33+
PATCH=$(echo $OLD_VERSION | cut -d. -f3)
34+
NEW_MINOR=$((MINOR + 1))
35+
NEW_VERSION="$MAJOR.$NEW_MINOR.$PATCH"
36+
sed -i "s/^version = .*/version = $NEW_VERSION/" pyproject.toml
37+
git config user.name "github-actions"
38+
git config user.email "github-actions@github.com"
39+
git commit -am "Bump version to $NEW_VERSION"
40+
git push origin develop
41+
42+
- id: version
43+
name: Add RC suffix in pyproject.toml
44+
run: |
45+
git checkout $GITHUB_REF_NAME
46+
OLD_VERSION=$(grep '^version =' pyproject.toml | awk '{print $3}')
47+
NEW_VERSION="$OLD_VERSION-RC"
48+
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
49+
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
50+
sed -i "s/^version = .*/version = $NEW_VERSION/" pyproject.toml
51+
git config user.name "github-actions"
52+
git config user.email "github-actions@github.com"
53+
git commit -am "Bump version to $NEW_VERSION"
54+
git push origin $GITHUB_REF_NAME
55+
56+
build-push-uat:
57+
name: "Build & push image"
58+
runs-on: ubuntu-latest
59+
needs: [version-bump-on-uat-create]
60+
steps:
61+
- name: Checkout code
62+
uses: actions/checkout@v4
63+
64+
- name: Log in to Docker Hub
65+
uses: docker/login-action@v3
66+
with:
67+
username: ${{ secrets.DOCKERHUB_USERNAME }}
68+
password: ${{ secrets.DOCKERHUB_TOKEN }}
69+
70+
- name: Build and push RC image
71+
run: |
72+
docker build -t ${{ vars.DOCKERHUB_ORGANIZATION }}/${{ var.DOCKERHUB_REPOSITORY }}:${{ needs.version-bump-on-uat-create.outputs.version }} .
73+
docker push ${{ vars.DOCKERHUB_ORGANIZATION }}/${{ var.DOCKERHUB_REPOSITORY }}:${{ needs.version-bump-on-uat-create.outputs.version }}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: SDLC - UAT push
2+
3+
on:
4+
push:
5+
branches:
6+
- 'uat/*'
7+
8+
jobs:
9+
version-bump-on-uat-push:
10+
name: "Bump application version"
11+
runs-on: ubuntu-latest
12+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/uat/') &&
13+
github.event.created == false
14+
outputs:
15+
version: ${{ steps.version.outputs.version }}
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- id: version
21+
name: Bump patch version in pyproject.toml
22+
run: |
23+
OLD_VERSION=$(grep '^version =' pyproject.toml | awk '{print $3}')
24+
MAJOR=$(echo $OLD_VERSION | cut -d. -f1)
25+
MINOR=$(echo $OLD_VERSION | cut -d. -f2)
26+
PATCH=$(echo $OLD_VERSION | cut -d. -f3)
27+
NEW_PATCH=$((PATCH + 1))
28+
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH-RC"
29+
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
30+
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
31+
sed -i "s/^version = .*/version = $NEW_VERSION/" pyproject.toml
32+
git config user.name "github-actions"
33+
git config user.email "github-actions@github.com"
34+
git commit -am "Bump version to $NEW_VERSION"
35+
git push origin $GITHUB_REF_NAME
36+
37+
build-push-uat:
38+
name: "Build & push image"
39+
runs-on: ubuntu-latest
40+
needs: [version-bump-on-uat-push]
41+
steps:
42+
- name: Checkout code
43+
uses: actions/checkout@v4
44+
45+
- name: Log in to Docker Hub
46+
uses: docker/login-action@v3
47+
with:
48+
username: ${{ secrets.DOCKERHUB_USERNAME }}
49+
password: ${{ secrets.DOCKERHUB_TOKEN }}
50+
51+
- name: Build and push RC image
52+
run: |
53+
docker build -t ${{ vars.DOCKERHUB_ORGANIZATION }}/${{ var.DOCKERHUB_REPOSITORY }}:${{ needs.version-bump-on-uat-push.outputs.version }} .
54+
docker push ${{ vars.DOCKERHUB_ORGANIZATION }}/${{ var.DOCKERHUB_REPOSITORY }}:${{ needs.version-bump-on-uat-push.outputs.version }}
55+
56+
57+
deploy:
58+
name: "Trigger deployment"
59+
needs: [build-push-uat]
60+
uses: ./.github/workflows/trigger-azure-pipeline.yml
61+
with:
62+
azure-organization: ${{ vars.AZURE_ORGANIZATION }}
63+
azure-project: ${{ vars.AZURE_PROJECT }}
64+
azure-pipeline-id: 1634
65+
secrets:
66+
azure-pat: ${{ secrets.AZURE_PAT }}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Trigger pipeline in Azure Pipelines
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
azure-organization:
7+
required: true
8+
type: string
9+
azure-project:
10+
required: true
11+
type: string
12+
azure-pipeline-id:
13+
required: true
14+
type: number
15+
secrets:
16+
azure-pat:
17+
required: true
18+
19+
jobs:
20+
deploy:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v4
25+
26+
- name: Trigger deploy
27+
run: |
28+
pipelineId=${{ inputs.azure-pipeline-id }}
29+
30+
IFS=',' read -ra pipelines <<< "$pipelineId"
31+
for pipeline in "${pipelines[@]}"; do
32+
jsonBody='{"variables": {"sha": {"isSecret": false, "value": "${{ github.sha }}"}, "tag": {"isSecret": false, "value": "${{ github.sha }}"}}}'
33+
contentLength=$(echo -n $jsonBody | wc -c)
34+
organization=${{ inputs.azure-organization }}
35+
project=${{ inputs.azure-project }}
36+
37+
echo Triggering deploy for pipeline $pipeline
38+
echo JSON body: $jsonBody
39+
40+
curl -f -v -L \
41+
-u ":${{ secrets.azure-pat }}" \
42+
-H "Content-Type: application/json" \
43+
-H "Content-Length: $contentLength" \
44+
-d "$jsonBody" \
45+
https://dev.azure.com/$organization/$project/_apis/pipelines/$pipeline/runs?api-version=7.1-preview.1
46+
if [ $? -ne 0 ]; then
47+
echo "Failed to trigger deploy for pipeline $pipeline"
48+
exit 1
49+
fi
50+
done

0 commit comments

Comments
 (0)