-
Notifications
You must be signed in to change notification settings - Fork 3
138 lines (118 loc) · 3.71 KB
/
job-post-merge.yml
File metadata and controls
138 lines (118 loc) · 3.71 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
name: GitHub Jobs Post Merge
on:
push:
branches:
- main
paths:
- ".github/workflows/job_**"
workflow_dispatch:
permissions:
contents: write
id-token: write
jobs:
get-file-names:
name: Get Names of Files Changed
runs-on: ubuntu-24.04
env:
SAM_CLI_TELEMETRY: 0
defaults:
run:
shell: bash
working-directory: .
outputs:
FILE_NAMES: ${{ steps.get-files.outputs.NAMES }}
steps:
- name: Checkout Repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: true
fetch-depth: 0
# This is ugly but can't get anything else to work
- name: Get File Names
id: get-files
run: |
files=$( git diff origin/main --name-only -- ./.github/workflows/job_** )
JSON="["
for file in ${files[@]}; do
echo $file
JSONline="\"$file\","
if [[ "$JSON" != *"$JSONline"* ]]; then
JSON="$JSON$JSONline"
fi
done
if [[ $JSON == *, ]]; then
JSON="${JSON%?}"
fi
JSON="$JSON]"
echo $JSON
echo "NAMES=$( echo "$JSON" )" >> $GITHUB_OUTPUT
create-tags:
name: Validate Versions and Create Tags
runs-on: ubuntu-24.04
needs: get-file-names
strategy:
matrix:
file_name: ${{ fromJSON(needs.get-file-names.outputs.FILE_NAMES) }}
env:
SAM_CLI_TELEMETRY: 0
FILE_NAME: ${{ matrix.file_name }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
defaults:
run:
shell: bash
working-directory: jobs
steps:
- name: Checkout Repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: true
fetch-depth: 0
- name: Setup NodeJS
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
cache: npm
cache-dependency-path: jobs/package-lock.json
node-version-file: jobs/.nvmrc
- name: Install Dependencies
run: |
npm clean-install
- name: Validate Job Name
id: job-name
run: |
name=$( yq .description ../$FILE_NAME | jq .name | tr -d '"' )
if [[ $FILE_NAME == ".github/workflows/job_$name" ]]; then
echo "Error: Job name does not match file name."
exit 1
fi
if [[ "$name" =~ ^[a-z0-9-]+$ ]]; then
echo "Valid job name."
echo "NAME=$name" >> $GITHUB_OUTPUT
else
echo "Error: Invalid job name."
exit 1
fi
- name: Get Version
id: get-version
run: |
version=$( yq .description ../$FILE_NAME | jq .version | tr -d '"' )
echo "VERSION=$version" >> $GITHUB_OUTPUT
- name: Validate Version
run: |
npm run validate-version $FILE_NAME
- name: Get Message
id: get-message
run: |
message=$( yq .description ../$FILE_NAME | jq .message )
echo "MESSAGE=$message" >> $GITHUB_OUTPUT
- name: Create and Push Tag
run: |
job_name=${{ steps.job-name.outputs.NAME }}
new_version=${{ steps.get-version.outputs.VERSION }}
git tag $job_name/$new_version
git push origin $job_name/$new_version
- name: Create GitHub Release
run: |
job_name=${{ steps.job-name.outputs.NAME }}
message=${{ steps.get-message.outputs.MESSAGE }}
new_version=${{ steps.get-version.outputs.VERSION }}
gh release create $job_name/$new_version --latest=false --notes "$message"