diff --git a/scripts/gitlab/update-chart.ps1 b/scripts/gitlab/update-chart.ps1 new file mode 100644 index 0000000..1e0691c --- /dev/null +++ b/scripts/gitlab/update-chart.ps1 @@ -0,0 +1,17 @@ +Install-Module -Name powershell-yaml -Confirm:$false -Force + +$template = (Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'= $ENV:CI_JOB_TOKEN } ` + -Uri "https://gitlab.com/api/v4/projects/45028985/repository/files/durpapi%2FChart.yaml/raw?ref=main") | ConvertFrom-Yaml +$template.version = $ENV:VERSION + +$body = @{ + branch = "main" + commit_message = "Update Chart" + content = "$($template | convertto-yaml)" +} | ConvertTo-Json + +Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'= $ENV:CI_JOB_TOKEN } ` + -ContentType "application/json" ` + -Method Put ` + -body $body ` + -Uri "https://gitlab.com/api/v4/projects/45028985/repository/files/durpapi%2FChart.yaml" diff --git a/scripts/render-job-templates.sh b/scripts/render-job-templates.sh index ed58932..fdeff61 100644 --- a/scripts/render-job-templates.sh +++ b/scripts/render-job-templates.sh @@ -2,6 +2,22 @@ #%%MULTILINE_YAML_START # render job-templates.yml from job-templates.tpl.yml set -euo pipefail +for pwsh in $(find ./scripts -name '*.ps1'); do + script=$(cat $pwsh) + sh_file="${pwsh%.ps1}.sh" + + # Escape double quotes and dollar signs + script="${script//\"/\\\"}" + script="${script//\$/\\\$}" + + pwsh_command="pwsh -c \"$script\"" + + echo '#!/bin/bash' > "$sh_file" + echo "$pwsh_command" >> "$sh_file" +done + + + for script in $(find ./scripts -name '*.sh'); do awk -v script_name="$(basename "$script")" ' NR==1 && /^#!/ {printf("# Begin of %s\n",script_name); next} # strip shebang in first line, print head comment diff --git a/templates/gitlab.tpl.yml b/templates/gitlab.tpl.yml index 013054c..208ca7e 100644 --- a/templates/gitlab.tpl.yml +++ b/templates/gitlab.tpl.yml @@ -6,3 +6,18 @@ expire_in: 1 hour paths: - $CI_PROJECT_DIR/output + +.gitlab-deploy: + stage: deploy + image: mcr.microsoft.com/powershell:latest + script: + - ./scripts/gitlab/update-chart.sh + environment: + name: production + url: https://api.durp.info/goapi + rules: + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ '/^release/' + when: manual + needs: + - job: version + artifacts: true