Skip to content

Commit bf6475b

Browse files
authored
Added actions (#2)
* Added build actions * OPS-3 updated backend source
1 parent e2940c6 commit bf6475b

File tree

13 files changed

+554
-1
lines changed

13 files changed

+554
-1
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Build Backend
2+
3+
on:
4+
push:
5+
paths: ["apps/backend/**", ".github/workflows/build-backend.yml"]
6+
workflow_dispatch:
7+
8+
env:
9+
# kosli commands picks up org, flow, trail and api-token from these environment variables
10+
KOSLI_ORG: kosli-public
11+
KOSLI_FLOW: jira-example-backend
12+
KOSLI_TRAIL: ${{ github.sha }}
13+
KOSLI_API_TOKEN: "${{ secrets.KOSLI_PUBLIC_API_TOKEN }}"
14+
KOSLI_CLI_VERSION: "2.11.8"
15+
KOSLI_TEMPLATE_FILE: "apps/backend/kosli-template.yml"
16+
# KOSLI_DRY_RUN: true
17+
JIRA_BASE_URL: "https://kosli-team.atlassian.net"
18+
JIRA_USERNAME: ${{ secrets.KOSLI_JIRA_USERNAME }}
19+
JIRA_API_TOKEN: ${{ secrets.KOSLI_JIRA_API_TOKEN }}
20+
21+
jobs:
22+
begin-trail:
23+
name: Begin trail
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
28+
- name: Begin trail
29+
if: ${{ github.ref == 'refs/heads/main' }}
30+
uses: ./.github/workflows/composites/kosli-begin-trail
31+
with:
32+
kosli-trail: ${{ env.KOSLI_TRAIL }}
33+
kosli-template-file: ${{ env.KOSLI_TEMPLATE_FILE }}
34+
35+
jira-ticket:
36+
name: Jira ticket
37+
needs: [begin-trail]
38+
runs-on: ubuntu-latest
39+
steps:
40+
- uses: actions/checkout@v4
41+
42+
- name: Attest jira ticket
43+
uses: ./.github/workflows/composites/kosli-attest-jira
44+
with:
45+
jira-base-url: ${{ env.JIRA_BASE_URL }}
46+
jira-username: ${{ env.JIRA_USERNAME }}
47+
jira-api-token: ${{ env.JIRA_API_TOKEN }}
48+
jira-issue-fields: "summary,description"
49+
report-to-kosli: ${{ github.ref == 'refs/heads/main' }}
50+
51+
pull-request:
52+
name: Pull-request
53+
if: ${{ github.ref == 'refs/heads/main' }}
54+
needs: [begin-trail]
55+
runs-on: ubuntu-latest
56+
steps:
57+
- uses: actions/checkout@v4
58+
59+
- name: Attest GitHub pull-request
60+
uses: ./.github/workflows/composites/kosli-attest-pullrequest
61+
with:
62+
github-token: ${{ secrets.GITHUB_TOKEN }}
63+
assert: true
64+
65+
build:
66+
name: Build backend
67+
needs: [begin-trail]
68+
runs-on: ubuntu-latest
69+
outputs:
70+
fingerprint: ${{ steps.calculate_fingerprint.outputs.fingerprint }}
71+
steps:
72+
- uses: actions/checkout@v4
73+
74+
- name: Build backend
75+
run: echo "Here we could do some proper build"
76+
77+
- name: Attest artifact
78+
id: calculate_fingerprint
79+
if: ${{ github.ref == 'refs/heads/main' }}
80+
uses: ./.github/workflows/composites/kosli-attest-dir-artifact
81+
with:
82+
kosli-artifact-template-name: backend
83+
artifact-env-name: backend0001
84+
artifact-dir: apps/backend
85+
86+
assert-artifacts:
87+
name: Assert artifacts
88+
if: ${{ github.ref == 'refs/heads/main' && always() }}
89+
needs: [build, jira-ticket, pull-request]
90+
runs-on: ubuntu-latest
91+
steps:
92+
- name: Setup Kosli cli
93+
uses: kosli-dev/setup-cli-action@v2
94+
with:
95+
version:
96+
${{ env.KOSLI_CLI_VERSION }}
97+
98+
- name: Assert Artifacts
99+
run: |
100+
set -x
101+
EXIT_CODE=0
102+
kosli assert artifact --fingerprint ${{ needs.build.outputs.fingerprint }} || EXIT_CODE=1
103+
exit ${EXIT_CODE}
104+
105+
deploy-dev:
106+
name: Deploy backend development
107+
if: ${{ github.ref == 'refs/heads/main' }}
108+
needs: [build, assert-artifacts]
109+
environment: Development
110+
runs-on: ubuntu-latest
111+
steps:
112+
- name: Deploy to development
113+
run: echo "Here we could do a proper deploy to Development environment"
114+
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Build Frontend
2+
3+
on:
4+
push:
5+
paths: ["apps/frontend/**", ".github/workflows/build-frontend.yml"]
6+
workflow_dispatch:
7+
8+
env:
9+
# kosli commands picks up org, flow, trail and api-token from these environment variables
10+
KOSLI_ORG: kosli-public
11+
KOSLI_FLOW: jira-example-frontend
12+
KOSLI_TRAIL: ${{ github.sha }}
13+
KOSLI_API_TOKEN: "${{ secrets.KOSLI_PUBLIC_API_TOKEN }}"
14+
KOSLI_CLI_VERSION: "2.11.8"
15+
KOSLI_TEMPLATE_FILE: "apps/frontend/kosli-template.yml"
16+
# KOSLI_DRY_RUN: true
17+
JIRA_BASE_URL: "https://kosli-team.atlassian.net"
18+
JIRA_USERNAME: ${{ secrets.KOSLI_JIRA_USERNAME }}
19+
JIRA_API_TOKEN: ${{ secrets.KOSLI_JIRA_API_TOKEN }}
20+
21+
jobs:
22+
begin-trail:
23+
name: Begin trail
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
28+
- name: Begin trail
29+
if: ${{ github.ref == 'refs/heads/main' }}
30+
uses: ./.github/workflows/composites/kosli-begin-trail
31+
with:
32+
kosli-trail: ${{ env.KOSLI_TRAIL }}
33+
kosli-template-file: ${{ env.KOSLI_TEMPLATE_FILE }}
34+
35+
jira-ticket:
36+
name: Jira ticket
37+
needs: [begin-trail]
38+
runs-on: ubuntu-latest
39+
steps:
40+
- uses: actions/checkout@v4
41+
42+
- name: Attest jira ticket
43+
uses: ./.github/workflows/composites/kosli-attest-jira
44+
with:
45+
jira-base-url: ${{ env.JIRA_BASE_URL }}
46+
jira-username: ${{ env.JIRA_USERNAME }}
47+
jira-api-token: ${{ env.JIRA_API_TOKEN }}
48+
jira-issue-fields: "summary,description"
49+
report-to-kosli: ${{ github.ref == 'refs/heads/main' }}
50+
51+
pull-request:
52+
name: Pull-request
53+
if: ${{ github.ref == 'refs/heads/main' }}
54+
needs: [begin-trail]
55+
runs-on: ubuntu-latest
56+
steps:
57+
- uses: actions/checkout@v4
58+
59+
- name: Attest GitHub pull-request
60+
uses: ./.github/workflows/composites/kosli-attest-pullrequest
61+
with:
62+
github-token: ${{ secrets.GITHUB_TOKEN }}
63+
assert: true
64+
65+
build:
66+
name: Build frontend
67+
needs: [begin-trail]
68+
runs-on: ubuntu-latest
69+
outputs:
70+
fingerprint: ${{ steps.calculate_fingerprint.outputs.fingerprint }}
71+
steps:
72+
- uses: actions/checkout@v4
73+
74+
- name: Build frontend
75+
run: echo "Here we could do some proper build"
76+
77+
- name: Attest artifact
78+
id: calculate_fingerprint
79+
if: ${{ github.ref == 'refs/heads/main' }}
80+
uses: ./.github/workflows/composites/kosli-attest-dir-artifact
81+
with:
82+
kosli-artifact-template-name: frontend
83+
artifact-env-name: frontend0002
84+
artifact-dir: apps/frontend
85+
86+
assert-artifacts:
87+
name: Assert artifacts
88+
if: ${{ github.ref == 'refs/heads/main' && always() }}
89+
needs: [build, jira-ticket, pull-request]
90+
runs-on: ubuntu-latest
91+
steps:
92+
- name: Setup Kosli cli
93+
uses: kosli-dev/setup-cli-action@v2
94+
with:
95+
version:
96+
${{ env.KOSLI_CLI_VERSION }}
97+
98+
- name: Assert Artifacts
99+
run: |
100+
set -x
101+
EXIT_CODE=0
102+
kosli assert artifact --fingerprint ${{ needs.build.outputs.fingerprint }} || EXIT_CODE=1
103+
exit ${EXIT_CODE}
104+
105+
deploy-dev:
106+
name: Deploy frontend development
107+
if: ${{ github.ref == 'refs/heads/main' }}
108+
needs: [build, assert-artifacts]
109+
environment: Development
110+
runs-on: ubuntu-latest
111+
steps:
112+
- name: Deploy to development
113+
run: echo "Here we could do a proper deploy to Development environment"
114+
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Kosli attest dir artifact
2+
3+
# Input is an artifact-directory that contains SW that shall be deployed at some later stage.
4+
# - Calculates the fingerprint of the content in the directory.
5+
# - Attest to kosli that an artifact with given fingerprint has been created.
6+
# https://docs.kosli.com/client_reference/kosli_attest_artifact/
7+
8+
inputs:
9+
# The Following environment variables must be set in your GitHub action
10+
# before using this composite
11+
# env:
12+
# KOSLI_ORG: kosli
13+
# KOSLI_FLOW: your-flow-name
14+
# KOSLI_TRAIL: your-trail-name (often git-commit-sha)
15+
# KOSLI_API_TOKEN: "${{ secrets.KOSLI_API_TOKEN }}"
16+
# KOSLI_CLI_VERSION: 2.11.6
17+
kosli-artifact-template-name:
18+
description: "Name of the artifact in kosli template-file. Often something generic like 'frontend'"
19+
required: true
20+
artifact-env-name:
21+
description: "Name of the artifact used when running in an environment. Often something like 'wezzajjgadwa0005'"
22+
required: true
23+
artifact-dir:
24+
description: "Directory where artifact is stored"
25+
required: true
26+
debug:
27+
description: "Set to true to include more debugging information. Including fingerprint calculation of artifact"
28+
required: false
29+
30+
outputs:
31+
fingerprint:
32+
description: "Fingerprint of artifact"
33+
value: ${{ steps.calculate_fingerprint.outputs.fingerprint }}
34+
35+
runs:
36+
using: "composite"
37+
steps:
38+
- name: Setup Kosli cli
39+
uses: kosli-dev/setup-cli-action@v2
40+
with:
41+
version:
42+
${{ env.KOSLI_CLI_VERSION }}
43+
44+
- name: Calculate fingerprint
45+
shell: bash
46+
id: calculate_fingerprint
47+
run: |
48+
set -x
49+
ARTIFACT_FINGERPRINT=$(kosli fingerprint --artifact-type dir ${{ inputs.artifact-dir }})
50+
echo "KOSLI_FINGERPRINT=${ARTIFACT_FINGERPRINT}" >> $GITHUB_ENV
51+
echo "fingerprint=${ARTIFACT_FINGERPRINT}" >> $GITHUB_OUTPUT
52+
echo "Calculated fingerprint: ${ARTIFACT_FINGERPRINT}"
53+
if [ "${{ inputs.debug }}" == "true" ]; then
54+
kosli fingerprint --artifact-type dir ${{ inputs.artifact-dir }} --debug
55+
fi
56+
57+
- name: Attest artifact
58+
shell: bash
59+
run: |
60+
set -x
61+
kosli attest artifact ${{ inputs.artifact-env-name }} \
62+
--name ${{ inputs.kosli-artifact-template-name }} \
63+
--fingerprint ${{ env.KOSLI_FINGERPRINT }}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Kosli Attest Jira
2+
3+
# Attest jira ticket.
4+
# https://docs.kosli.com/client_reference/kosli_attest_jira/
5+
# The possible fields in the jira-issue-fields comes from the Jira API
6+
# https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issues/#api-rest-api-2-issue-issueidorkey-get-request
7+
8+
9+
inputs:
10+
# The Following environment variables must be set in your GitHub action
11+
# before using this composite
12+
# env:
13+
# KOSLI_ORG: kosli
14+
# KOSLI_FLOW: your-flow-name
15+
# KOSLI_TRAIL: your-trail-name (often git-commit-sha)
16+
# KOSLI_API_TOKEN: "${{ secrets.KOSLI_API_TOKEN }}"
17+
# KOSLI_CLI_VERSION: 2.11.6
18+
jira-base-url:
19+
description: "Jira base url for your org (often https://kosli-team.atlassian.net)"
20+
required: true
21+
jira-username:
22+
description: "Jira user-name"
23+
required: true
24+
jira-api-token:
25+
description: "Jira API token"
26+
required: true
27+
jira-issue-fields:
28+
description: "List of fields to include from Jira ticket. See comment at top of file."
29+
required: false
30+
report-to-kosli:
31+
description: "Report to kosli if jira ticket exists. Normally set this to 'false' on branches"
32+
required: false
33+
default: "true"
34+
35+
36+
runs:
37+
using: "composite"
38+
steps:
39+
- name: Setup Kosli cli
40+
uses: kosli-dev/setup-cli-action@v2
41+
with:
42+
version:
43+
${{ env.KOSLI_CLI_VERSION }}
44+
45+
- name: Attest Jira ticket
46+
shell: bash
47+
run: |
48+
set -x
49+
JIRA_ISSUE_ARG=""
50+
if [ -n "${{ inputs.jira-issue-fields }}" ]; then
51+
JIRA_ISSUE_ARG="--jira-issue-fields ${{ inputs.jira-issue-fields }}"
52+
fi
53+
54+
if [ "${{ inputs.report-to-kosli }}" == "false" ]; then
55+
# Currently the kosli attest jira command is missing a feature to not report the jira ticket,
56+
# so use a grep for now
57+
kosli attest jira \
58+
--name jira-ticket \
59+
--jira-base-url ${{ inputs.jira-base-url }} \
60+
--jira-username ${{ inputs.jira-username }} \
61+
--jira-api-token ${{ inputs.jira-api-token }} \
62+
--ignore-branch-match \
63+
--assert --dry-run 2>&1 | grep "no Jira references are found" && exit 1 || exit 0
64+
else
65+
kosli attest jira \
66+
--name jira-ticket \
67+
--jira-base-url ${{ inputs.jira-base-url }} \
68+
--jira-username ${{ inputs.jira-username }} \
69+
--jira-api-token ${{ inputs.jira-api-token }} \
70+
--ignore-branch-match \
71+
--assert \
72+
${JIRA_ISSUE_ARG}
73+
fi

0 commit comments

Comments
 (0)