-
Notifications
You must be signed in to change notification settings - Fork 0
110 lines (100 loc) · 3.75 KB
/
synchronize-package-commit-list.yaml
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
name: Synchronize package commit list
on:
workflow_call:
inputs:
after_sha:
description: Latest synchronized Git sha
type: string
required: true
until_sha:
description: Latest Git sha to synchronize
type: string
required: true
package_directory:
description: Path to the package inside the current repository
type: string
required: true
repository_organization:
description: Target repository organization
type: string
required: true
repository_name:
description: Target repository name
type: string
required: true
repository_branch:
description: Target repository branch
type: string
required: true
repository_tag:
description: Target repository tag
type: string
required: false
permissions: {}
jobs:
metadata:
name: Metadata
runs-on: ubuntu-latest
outputs:
commits: ${{ steps.matrix-generator.outputs.result }}
steps:
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: List commits infos
id: list-commits
run: |
# Retrieve commit range
git show -s --format='["%H", "%an", "%ae"]' '${{ inputs.after_sha }}...${{ inputs.until_sha }}' | tr "\n" "," | tee list.json
echo '[]' | tee -a list.json
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "list=[$(cat list.json)]" >> $GITHUB_OUTPUT
- name: Generate matrix
id: matrix-generator
uses: actions/github-script@v6
with:
script: |
const commitInfosList = JSON.parse('${{ steps.list-commits.outputs.list }}')
.filter(item => item.length > 0);
if (commitInfosList.length === 0) {
return [];
}
const rawTag = '${{ inputs.repository_tag }}'.trim();
const tag = rawTag.length > 0 ? rawTag : undefined;
const list = [];
for (const key in commitInfosList) {
const isFirstCommit = Number.parseInt(key) === 0;
const commitInfos = commitInfosList[key];
list.push({
sha: commitInfos[0],
author_name: commitInfos[1],
author_email: commitInfos[2],
// Tag repository only on latest commit (=first commit of the list) !
repository_tag: isFirstCommit && tag ? tag : undefined
});
}
// Output the list as reverse order (with first commit to synchronize as first element)
list.reverse();
console.log(`after=${JSON.stringify(list)}`);
return list;
main:
name: From ${{ matrix.commit.sha }}
needs: [ metadata ]
if: ${{ needs.metadata.outputs.commits != '[]' && needs.metadata.outputs.commits != '' }}
strategy:
fail-fast: true # Stop as soon as there is an error, so it can be resumed
max-parallel: 1 # Synchro must be done commit by commit !
matrix:
commit: ${{ fromJson(needs.metadata.outputs.commits) }}
uses: ./.github/workflows/synchronize-package-commit.yaml
secrets: inherit
with:
sha: ${{ matrix.commit.sha }}
author_name: ${{ matrix.commit.author_name }}
author_email: ${{ matrix.commit.author_email }}
package_directory: ${{ inputs.package_directory }}
repository_organization: ${{ inputs.repository_organization }}
repository_name: ${{ inputs.repository_name }}
repository_branch: ${{ inputs.repository_branch }}
repository_tag: ${{ matrix.commit.repository_tag }}