-
Notifications
You must be signed in to change notification settings - Fork 20
202 lines (181 loc) · 8.34 KB
/
publication-request.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
name: Build IG and Create Publication Request JSON
on:
issues:
types: [opened, edited]
jobs:
# Job 1: Call the reusable workflow for building the IG
call_build:
uses: WorldHealthOrganization/smart-base/.github/workflows/ghbuild.yml@main
# Job 2: Upload qa.json as an artifact
upload_artifacts:
runs-on: ubuntu-latest
needs: call_build # This ensures the IG build completes before uploading artifacts
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Download qa.json artifact
uses: actions/download-artifact@v3
with:
name: qa-json-artifact
# List files in the output directory to confirm qa.json is there
- name: List output directory contents
run: ls -Rla .
# Check if qa.json exists in the output folder
- name: Check if qa.json exists
run: |
if [ -f "qa.json" ]; then
echo "qa.json file exists, proceeding with upload."
echo "::set-output name=qa-found::true"
else
echo "Error: qa.json file not found!"
echo "::set-output name=qa-found::false"
exit 1 # Exit if qa.json is not found
fi
# Upload qa.json as an artifact if it exists
- name: Upload qa.json artifact
uses: actions/upload-artifact@v3
with:
name: qa-json-artifact
path: qa.json # Path to the qa.json file located in the output directory
# Job 3: Process qa.json (Create publication-request.json)
process_qa_json:
if: contains(github.event.issue.labels.*.name, 'publication-request')
runs-on: ubuntu-latest
needs: upload_artifacts # Ensure the artifact upload completes before this job
steps:
- name: Checkout repository
uses: actions/checkout@v2
# Fetch all branches from the remote
- name: Fetch all branches
run: git fetch --all
# Create and checkout release-candidate branch if it doesn't exist
- name: Create and checkout release-candidate if it doesn't exist
run: |
if git rev-parse --verify origin/release-candidate; then
git checkout release-candidate
else
git checkout -b release-candidate
git push origin release-candidate
fi
# Download qa.json artifact
- name: Download qa.json artifact
uses: actions/download-artifact@v3
with:
name: qa-json-artifact
# Capture GitHub event payload in an environment variable and log it
- name: Set GitHub event payload to environment variable
env:
GITHUB_EVENT_PAYLOAD: ${{ toJson(github.event) }}
run: |
echo "Logging GitHub event payload..."
echo "$GITHUB_EVENT_PAYLOAD"
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
# Extract data from issue.body using sed
- name: Extract form data
run: |
BODY="${{ github.event.issue.body }}"
MODE=$(echo "$BODY" | sed -n '/^### Release Mode/{n;:a;/^\s*$/!{p;q};n;ba}')
STATUS=$(echo "$BODY" | sed -n '/^### Release Status/{n;:a;/^\s*$/!{p;q};n;ba}')
SEQUENCE=$(echo "$BODY" | sed -n '/^### Sequence Name/{n;:a;/^\s*$/!{p;q};n;ba}')
DESCRIPTION=$(echo "$BODY" | sed -n '/^### Description of the Release/{n;:a;/^\s*$/!{p;q};n;ba}')
CHANGES=$(echo "$BODY" | sed -n '/^### Link to Changes/{n;:a;/^\s*$/!{p;q};n;ba}')
FIRST_RELEASE=$(echo "$BODY" | grep -q "Yes, this is the first release" && echo "true" || echo "false")
TITLE=$(echo "$BODY" | sed -n '/^### Title (for first release only)/{n;:a;/^\s*$/!{p;q};n;ba}')
CATEGORY=$(echo "$BODY" | sed -n '/^### Category (for first release only)/{n;:a;/^\s*$/!{p;q};n;ba}')
INTRODUCTION=$(echo "$BODY" | sed -n '/^### Introduction (for first release only)/{n;:a;/^\s*$/!{p;q};n;ba}')
echo "Mode: $MODE"
echo "Status: $STATUS"
echo "Sequence: $SEQUENCE"
echo "Description: $DESCRIPTION"
echo "Changes: $CHANGES"
echo "First Release: $FIRST_RELEASE"
echo "Title: $TITLE"
echo "Category: $CATEGORY"
echo "Introduction: $INTRODUCTION"
echo "MODE=$MODE" >> $GITHUB_ENV
echo "STATUS=$STATUS" >> $GITHUB_ENV
echo "SEQUENCE=$SEQUENCE" >> $GITHUB_ENV
echo "DESCRIPTION=$DESCRIPTION" >> $GITHUB_ENV
echo "CHANGES=$CHANGES" >> $GITHUB_ENV
echo "FIRST_RELEASE=$FIRST_RELEASE" >> $GITHUB_ENV
echo "TITLE=$TITLE" >> $GITHUB_ENV
echo "CATEGORY=$CATEGORY" >> $GITHUB_ENV
echo "INTRODUCTION=$INTRODUCTION" >> $GITHUB_ENV
# Extract values from qa.json
- name: Extract values from qa.json
run: |
PACKAGE_ID=$(jq -r '.["package-id"]' ./qa.json)
TITLE=$(jq -r '.["title"]' ./qa.json)
VERSION=$(jq -r '.["ig-ver"]' ./qa.json)
STATUS=$(jq -r '.["status"]' ./qa.json)
URL=$(jq -r '.["url"]' ./qa.json)
PATH_VALUE="${URL%%/ImplementationGuide*}/$VERSION"
echo "PACKAGE_ID=$PACKAGE_ID" >> $GITHUB_ENV
echo "TITLE=$TITLE" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "STATUS=$STATUS" >> $GITHUB_ENV
echo "PATH_VALUE=$PATH_VALUE" >> $GITHUB_ENV
# Generate ci-build URL
- name: Generate ci-build URL
run: |
REPO_NAME="${{ github.repository }}"
CI_BUILD_URL="http://worldhealthorganization.github.io/$REPO_NAME"
echo "CI_BUILD_URL=$CI_BUILD_URL" >> $GITHUB_ENV
# Create publication-request.json in the root folder
- name: Create publication-request.json
run: |
cat <<EOF > ./publication-request.json
{
"package-id": "${{ env.PACKAGE_ID }}",
"title": "${{ env.TITLE }}",
"version": "${{ env.VERSION }}",
"path": "${{ env.PATH_VALUE }}",
"status": "${{ env.STATUS }}",
"mode": "${{ env.MODE }}",
"sequence": "${{ env.SEQUENCE }}",
"desc": "${{ env.DESCRIPTION }}",
"changes": "${{ env.CHANGES }}",
"first": "${{ env.FIRST_RELEASE }}",
"category": "${{ env.CATEGORY }}",
"introduction": "${{ env.INTRODUCTION }}",
"ci-build": "${{ env.CI_BUILD_URL }}"
}
EOF
echo "publication-request.json created in the root directory."
# Configure Git user identity
- name: Configure Git user
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "GitHub Actions Bot"
# Check if there are changes and commit only the publication-request.json file
- name: Check and commit changes
run: |
git add ./publication-request.json
if git diff-index --quiet HEAD; then
echo "No changes to commit."
else
git commit -m "Created publication-request.json from issue #${{ github.event.issue.number }} [skip workflow]"
git push origin release-candidate
fi
# Post a comment in the issue with a link and content of the publication-request.json
- name: Post a comment to the issue
run: |
JSON_CONTENT=$(cat ./publication-request.json | jq -Rs .)
ISSUE_NUMBER=${{ github.event.issue.number }}
COMMENT_BODY="publication-request.json created in the branch [release-candidate](https://github.com/${{ github.repository }}/blob/release-candidate/publication-request.json) with this content: \n\n\`\`\`json\n$JSON_CONTENT\n\`\`\`"
curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
--data "{\"body\":\"$COMMENT_BODY\"}" \
"https://api.github.com/repos/${{ github.repository }}/issues/${ISSUE_NUMBER}/comments" || exit 1
# Add the "Build OK" label to the issue
- name: Add "Build OK" label
run: |
ISSUE_NUMBER=${{ github.event.issue.number }}
curl -s -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
--data '{"labels":["Build OK"]}' \
"https://api.github.com/repos/${{ github.repository }}/issues/${ISSUE_NUMBER}/labels"