Skip to content

Commit

Permalink
feat: Add unit test to PR workflow to make sure enhancements are back…
Browse files Browse the repository at this point in the history
…ward compatible. (#27)
  • Loading branch information
mishraomp authored Nov 19, 2023
1 parent a858a39 commit 8ccde04
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 1 deletion.
44 changes: 44 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: On Pull Request to Main
on:
pull_request:
branches:
- main
jobs:
validate-changes:
if: '!github.event.pull_request.head.repo.fork'
runs-on: ubuntu-22.04
strategy:
matrix:
include:
- repo_name: quickstart-openshift
params: --set-string global.secrets.databasePassword=test --set-string global.secrets.databaseUser=test --set-string global.secrets.databasePassword=databaseName
- repo_name: pubcode
params: ''
timeout-minutes: 2
steps:
- uses: actions/checkout@v4
with:
path: ./helm-service
- uses: actions/checkout@v4
with:
repository: bcgov/${{ matrix.repo_name }}
ref: main
path: ./${{ matrix.repo_name }}
- name: Add Node
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Dependencies
run: |
cd ./helm-service/util
npm ci
- name: Execute Program
run: |
DESTINATION_REPO=${{ matrix.repo_name }} node ./helm-service/util/index.js
- name: Validate Changes
shell: bash
run: |
cd ./${{ matrix.repo_name }}/charts/${{ matrix.repo_name }}
helm dependency update
helm template ${{ matrix.repo_name }} --debug ${{ matrix.params }} .
2 changes: 1 addition & 1 deletion charts/component/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0
version: 0.1.1

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
3 changes: 3 additions & 0 deletions charts/component/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ helm.sh/chart: {{ include "component.chart" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
{{- if and .Values.image .Values.image.tag }}
app.kubernetes.io/image-tag: {{ .Values.image.tag | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

Expand Down
26 changes: 26 additions & 0 deletions util/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as fs from "fs";
import jsYaml from "js-yaml";

const fs_promises = fs.promises;
const destination_repo = process.env.DESTINATION_REPO|| "quickstart-openshift";
const sourceDirectory = ".";
const main = async () => {
const chartYaml = await fs_promises.readFile("./helm-service/charts/component/Chart.yaml");
const destChartYaml = await fs_promises.readFile(`./${destination_repo}/charts/${destination_repo}/Chart.yaml`);
const chartYamlToJSON =jsYaml.load(chartYaml);
const version = chartYamlToJSON.version;
const destChartYamlToJSON =jsYaml.load(destChartYaml);
const dependencies = destChartYamlToJSON.dependencies;
let newDependencies = [];
for(const element of dependencies){
if(element.name === 'component'){
element.version = version;
element.repository = `file://../../../helm-service/charts/component`;
}
newDependencies.push(element);
}
destChartYamlToJSON.dependencies = newDependencies;
const newDestChartYaml = jsYaml.dump(destChartYamlToJSON);
await fs_promises.writeFile(`./${destination_repo}/charts/${destination_repo}/Chart.yaml`, newDestChartYaml);
}
await main();
31 changes: 31 additions & 0 deletions util/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions util/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "util",
"version": "1.0.0",
"type": "module",
"main": "index.js",
"dependencies": {
"js-yaml": "^4.1.0"
}
}

0 comments on commit 8ccde04

Please sign in to comment.