-
Notifications
You must be signed in to change notification settings - Fork 29
126 lines (110 loc) · 4.59 KB
/
update-changelog-dates.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
name: Update changelog dates
on:
workflow_call:
inputs:
date:
description: 'The date this component was deployed to the environment.'
required: true
type: string
version:
description: 'Version of the component that has been deployed to the environment.'
required: true
type: string
component:
description: 'The name of the component that has been deployed to the environment.'
required: true
type: string
workflow_dispatch:
inputs:
date:
description: 'The date this component was deployed to the environment.'
required: true
type: string
default: '2024-06-05'
version:
description: 'Version of the component that has been deployed to the environment.'
default: '1020.0.10'
required: true
type: string
component:
description: 'The name of the component that has been deployed to the environment.'
required: true
default: 'ui-c8y'
type: string
concurrency:
group: ${{ github.workflow }}-${{ inputs.component }}
cancel-in-progress: false
jobs:
updateDates:
name: Update changelog dates
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: logging-inputs
run: echo ${{inputs.component}} ${{inputs.version}} ${{inputs.date}}
- name: Set git user
run: |
git config --global user.name "c8y-docs-automations[bot]"
git config --global user.email "c8y-docs-automations[bot]@users.noreply.github.com"
- name: Creating github access token
id: token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ vars.C8Y_DOCS_AUTOMATIONS_APP_ID }}
private-key: ${{ secrets.C8Y_DOCS_AUTOMATIONS_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
- name: Checking out
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.token.outputs.token }}
- name: Generate branch name
id: branch-name
run: echo "branch-name=update-changelog-dates/${{ inputs.component }}_${{ inputs.version }}_${{ inputs.date }}" | sed 's/\s/_/g' | sed 's/:/_/g' >> $GITHUB_OUTPUT
- name: Checkout branch
run: |
git checkout -b "${{ steps.branch-name.outputs.branch-name }}"
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Update changelog files
run: |
cd add-release-dates
npm ci
npm start "${{ inputs.component }}" "${{ inputs.version }}" "${{ inputs.date }}"
- name: Git add
id: git-add
run: |
git add content/change-logs
echo "stagedFiles=$(git diff --cached --numstat | wc -l)" >> $GITHUB_OUTPUT
- name:
if: ${{ fromJSON(steps.git-add.outputs.stagedFiles) > 0 }}
run: |
echo "::notice :: Updated ${{ steps.git-add.outputs.stagedFiles }} changelog entries for ${{ inputs.component }}@${{ inputs.version }}"
- name:
if: ${{ fromJSON(steps.git-add.outputs.stagedFiles) == 0 }}
run: |
echo "::warning :: No new changelog entries found for ${{ inputs.component }}@${{ inputs.version }}"
- name: Git commit
if: ${{ fromJSON(steps.git-add.outputs.stagedFiles) > 0 }}
run: |
git commit -m "Update ${{ inputs.component }} changelog dates to ${{ inputs.date }} as version ${{ inputs.version }} was released"
- name: Git push
if: ${{ fromJSON(steps.git-add.outputs.stagedFiles) > 0 }}
id: git-push
run: |
if [[ -z $(git ls-remote --heads origin "${{ steps.branch-name.outputs.branch-name }}") ]];
then
git push -u origin "${{ steps.branch-name.outputs.branch-name }}"
echo "uniqueBranchFlag=true" >> $GITHUB_OUTPUT
else
echo "::warning :: ${{ steps.branch-name.outputs.branch-name }} branch already exists, no new branch created for this change"
echo "uniqueBranchFlag=false" >> $GITHUB_OUTPUT
fi
- name: Create pull request
if: ${{ fromJSON(steps.git-add.outputs.stagedFiles) > 0 && steps.git-push.outputs.uniqueBranchFlag == 'true' }}
env:
GITHUB_TOKEN: ${{ steps.token.outputs.token }}
run: |
gh pr create -B ${{ github.ref }} -H "${{ steps.branch-name.outputs.branch-name }}" --title 'Update ${{ inputs.component }} changelog dates to ${{ inputs.date }} as version ${{ inputs.version }} was released' --body 'Created by [Github action](${{ github.server_url }}/${{ github.repository_owner }}/${{ github.event.repository.name }}/actions/workflows/update-changelog-dates.yml)' --assignee BeateRixen