Skip to content

Commit cc0b684

Browse files
michalby24michsi24netanelC
authored
feat: create an update-site-values pr MAPCO-9149 (#101)
* feat: add update-charts-pr action and workflow for chart updates * feat: update update-charts-pr action workflow and add README documentation * style: remove unnecessary line from README.md * feat: update update-charts-pr action to use update_path input and improve README documentation * Update actions/update-charts-pr/README.md Co-authored-by: Netanel Cohen <34451523+netanelC@users.noreply.github.com> * docs: update README and action.yaml to clarify inputs and improve documentation * feat: update update-charts-pr action to support multiple YAML paths and improve input descriptions * chore: update release manifest to include actions/update-charts-pr version 0.1.0 * docs: update example in README to use 'update_paths' for multiple YAML files * refactor: replace update_paths input with paths and update docs and workflow accordingly * docs: replace update_paths input with paths in readme * Update actions/update-charts-pr/README.md Co-authored-by: Netanel Cohen <34451523+netanelC@users.noreply.github.com> * refactor: rename service_repo input to chart in update-charts-pr action * Update actions/update-charts-pr/action.yaml Co-authored-by: Netanel Cohen <34451523+netanelC@users.noreply.github.com> * fix: add repository input to test-update-charts-pr workflow * ci: switch from external yq cction to inline run step * ci: update create-pull-request action to v7 and add author/committer fields * ci: add environment input to control prod branch updates vs PR creation * ci: add reviewers and team_reviewers inputs to update-charts-pr action * ci: add assignees input to update-charts-pr action * ci: update environment input to be required in action.yaml * Update actions/update-charts-pr/action.yaml Co-authored-by: Netanel Cohen <34451523+netanelC@users.noreply.github.com> * Update .github/workflows/test-update-charts-pr.yml Co-authored-by: Netanel Cohen <34451523+netanelC@users.noreply.github.com> * ci: update action references in workflows and config * ci: seperate PR title and commit message generation * ci: remove unused team_reviewers input from action.yaml and README * ci: refine commit message format and update PR labels handling --------- Co-authored-by: michsi24 <michalby24@gmail.com> Co-authored-by: Netanel Cohen <34451523+netanelC@users.noreply.github.com>
1 parent 092564f commit cc0b684

5 files changed

Lines changed: 187 additions & 1 deletion

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Test update-charts-pr action
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
test-action:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout this repo
11+
uses: actions/checkout@v5
12+
13+
- name: Run update-charts-pr action
14+
uses: ./actions/update-chart-version
15+
with:
16+
tag: 0.0.0
17+
repository: test-site
18+
github_token: ${{ secrets.GH_PAT }}
19+
environment: dev
20+
chart: test-service-repo
21+
paths: |
22+
infra/environments/dev.yaml
23+
infra/environments/prod.yaml

.release-please-manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"actions/helm-lint": "1.1.0",
44
"actions/update-artifacts-file": "1.2.0",
55
"actions/init-npm": "1.2.0",
6-
"actions/validate-domain": "1.0.0"
6+
"actions/validate-domain": "1.0.0",
7+
"actions/update-chart-version": "0.1.0"
78
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Update site-values and create PR Action
2+
3+
This GitHub Action creates a PR for updating a chart version presented in a file.
4+
5+
---
6+
7+
## ✨ What It Does
8+
9+
- Checks out the target repository (default: `MapColonies/site-values`)
10+
- Sets `chartsVersions[service_repo] = tag` in the YAML file at `update_path`
11+
- Opens a pull request and applies optional labels
12+
13+
---
14+
15+
## 🛠 Inputs
16+
17+
| Name | Description | Required | Default |
18+
|----------------|----------------------------------------------------------------------------------------------|----------|---------------------------|
19+
| `tag` | Chart tag/version to set for the service (e.g., `1.2.3`) | ✅ Yes | |
20+
| `paths` | One or more YAML paths to update (e.g., `raster/environments/dev.yaml`)| ✅ Yes | |
21+
| `environment` | Deployment environment used for PR naming and messaging (`dev`, `prod`, etc.) | ✅ Yes | |
22+
| `github_token` | GitHub token with write access to the target repository | ✅ Yes | |
23+
| `repository` | Repository name (under `MapColonies/`) to update | ❌ No | `site-values` |
24+
| `branch` | Base branch of the target repository | ❌ No | `master` |
25+
| `chart` | Chart name to use as the key under `chartsVersions` | ❌ No | calling repo name |
26+
| `pr_labels` | Labels to apply on the created PR (comma separated) | ❌ No | |
27+
| `reviewers` | Comma-separated GitHub usernames to request review from (used only if non-empty) | ❌ No | |
28+
| `assignees` | Comma-separated GitHub usernames to assign to the PR (used only if non-empty) | ❌ No | |
29+
30+
> Branch naming: When `environment` is `prod`, the pull request branch will be named `prod`. Otherwise, the branch will be `<environment>-<chart>-<sha>` (e.g., `dev-my-service-<commit-sha>`).
31+
32+
---
33+
34+
## 🚀 Usage
35+
36+
<!-- x-release-please-start-version -->
37+
38+
```yaml
39+
- name: Update site-values and open PR
40+
uses: MapColonies/shared-workflows/actions/update-chart-version@update-chart-version-v1.0.0
41+
with:
42+
tag: 1.0.0
43+
paths: |
44+
infra/environments/dev.yaml
45+
common/environments/dev.yaml
46+
github_token: ${{ secrets.GH_PAT }}
47+
environment: dev
48+
```
49+
50+
<!-- x-release-please-end-version -->
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: "Update Chart Version in Target Repository"
2+
description: "Checks out the target repository, updates the chart tag for the current service, and opens a PR"
3+
4+
inputs:
5+
tag:
6+
description: "Chart tag (version) to set for this service"
7+
required: true
8+
paths:
9+
description: "One or more YAML paths to update"
10+
required: true
11+
chart:
12+
description: "Name of the chart to update in target repository"
13+
required: false
14+
default: ${{ github.event.repository.name }}
15+
environment:
16+
description: "Deployment environment"
17+
required: true
18+
github_token:
19+
description: "GitHub token with write access to the target repository"
20+
required: true
21+
repository:
22+
description: "Target repository"
23+
required: false
24+
default: "site-values"
25+
branch:
26+
description: "Target base branch in repository"
27+
required: false
28+
default: "master"
29+
pr_labels:
30+
description: "Labels to apply on the created PR"
31+
required: false
32+
assignees:
33+
description: "Comma-separated list of assignees to assign to the PR"
34+
required: false
35+
reviewers:
36+
description: "Comma-separated list of reviewers to request review from"
37+
required: false
38+
39+
runs:
40+
using: "composite"
41+
steps:
42+
- name: Checkout ${{ inputs.repository }} repo
43+
uses: actions/checkout@v5
44+
with:
45+
repository: MapColonies/${{ inputs.repository }}
46+
token: ${{ inputs.github_token }}
47+
path: ${{ inputs.repository }}
48+
ref: ${{ inputs.branch }}
49+
50+
- name: Update tags in ${{ inputs.repository }}
51+
shell: bash
52+
run: |
53+
set -euo pipefail
54+
55+
echo "Updating chartsVersions[\"${{ inputs.chart }}\"] to \"${{ inputs.tag }}\" in:"
56+
# Support newline or comma separated list
57+
echo '${{ inputs.paths }}' | tr ',' '\n' | while IFS= read -r relpath; do
58+
# skip empty lines
59+
[ -z "$relpath" ] && continue
60+
61+
# trim possible leading/trailing spaces
62+
relpath="$(echo "$relpath" | xargs)"
63+
64+
echo " - $relpath"
65+
yq eval -i \
66+
".chartsVersions[\"${{ inputs.chart }}\"] = \"${{ inputs.tag }}\"" \
67+
"${{ inputs.repository }}/$relpath"
68+
done
69+
70+
- name: Compute PR title and commit message
71+
shell: bash
72+
run: |
73+
set -euo pipefail
74+
75+
prefix=$([ "${{ inputs.environment }}" = "prod" ] && echo "deps" || echo "devdeps")
76+
commit_msg="${prefix}(${{ inputs.environment }}): update ${{ inputs.chart }} to ${{ inputs.tag }}"
77+
78+
if [ "${{ inputs.environment }}" = "prod" ]; then
79+
title="deps: prod changes"
80+
else
81+
title="$commit_msg"
82+
fi
83+
84+
echo "PR_COMMIT_MESSAGE=$commit_msg" >> "$GITHUB_ENV"
85+
echo "PR_TITLE=$title" >> "$GITHUB_ENV"
86+
87+
88+
- name: Create Pull Request
89+
uses: peter-evans/create-pull-request@v7
90+
with:
91+
path: ${{ inputs.repository }}
92+
token: ${{ inputs.github_token }}
93+
author: "mapcolonies[bot] <devops[bot]@mapcolonies.com>"
94+
committer: "mapcolonies[bot] <devops[bot]@mapcolonies.com>"
95+
assignees: ${{ inputs.assignees && inputs.assignees || '' }}
96+
reviewers: ${{ inputs.reviewers && inputs.reviewers || '' }}
97+
commit-message: ${{ env.PR_COMMIT_MESSAGE }}
98+
title: ${{ env.PR_TITLE }}
99+
body: |
100+
Trigger commit: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
101+
102+
Updated files:
103+
${{ inputs.paths }}
104+
labels: ${{ inputs.pr_labels && inputs.pr_labels || '' }}, ${{ inputs.environment }}, ${{ inputs.environment == 'dev' && 'auto-merge' || '' }}
105+
branch: "${{ inputs.environment == 'prod' && 'prod' ||
106+
format('{0}-{1}-{2}', inputs.environment, inputs.chart, github.sha) }}"
107+
base: ${{ inputs.branch }}

release-please-config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
"release-type": "simple",
2424
"package-name": "validate-domain",
2525
"extra-files": ["README.md"]
26+
},
27+
"actions/update-chart-version": {
28+
"release-type": "simple",
29+
"package-name": "update-chart-version",
30+
"extra-files": ["README.md"]
2631
}
2732
}
2833
}

0 commit comments

Comments
 (0)