-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
381 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Infos release artifacts | ||
|
||
on: | ||
repository_dispatch: | ||
types: [trigger-artifact-workflow] | ||
|
||
jobs: | ||
store_artifacts: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Access data from GitLab payload | ||
run: | | ||
echo '${{ toJSON(github.event.client_payload) }}' > artifact.json | ||
cat artifact.json | ||
- name: Upload JSON as artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: gitlab-data-artifact | ||
path: artifact.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
name: Automated Slack message | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
slack_message: | ||
name: Slack message | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Download release artifact | ||
uses: dawidd6/action-download-artifact@v6 | ||
with: | ||
name: gitlab-data-artifact | ||
github_token: ${{ github.token }} | ||
workflow: info-release.yml | ||
- name: Display artifact content | ||
run: cat artifact.json | ||
- name: Slack Markdown Converter | ||
if: github.event.release.body | ||
id: convert | ||
uses: LoveToKnow/[email protected] | ||
with: | ||
text: ${{ github.event.release.body }} | ||
- name: Prepare and send Slack message | ||
env: | ||
EVENT_CONTEXT: ${{ toJSON(github.event) }} | ||
CONVERTED_TEXT: ${{ steps.convert.outputs.text }} | ||
run: | | ||
node <<EOF | ||
const { tickets } = require('./artifact.json'); | ||
(async () => { | ||
const project = "HiPay Enterprise SDK Android"; | ||
const payload = { | ||
channel: "${{ vars.SLACK_CHANNEL_ID }}", | ||
blocks: [ | ||
{ | ||
"type": "section", | ||
"text": { | ||
"type": "mrkdwn", | ||
"text": "*[NEW]* " + project + " - ${{ github.event.release.tag_name }}", | ||
}, | ||
"accessory": { | ||
"type": "button", | ||
"text": { | ||
"type": "plain_text", | ||
"text": "Show release :rocket:", | ||
"emoji": true | ||
}, | ||
"url": "${{ github.event.release.html_url }}" | ||
} | ||
}, | ||
{ | ||
"type": "section", | ||
"text": { | ||
"type": "mrkdwn", | ||
"text": ":clipboard: Tickets JIRA :" | ||
} | ||
}, | ||
{ | ||
"type": "rich_text", | ||
"elements": [ | ||
{ | ||
"type": "rich_text_list", | ||
"style": "bullet", | ||
"elements": [] | ||
} | ||
] | ||
} | ||
] | ||
}; | ||
tickets.forEach((ticket) => { | ||
ticket = ticket.toUpperCase(); | ||
payload.blocks[2].elements[0].elements.push({ | ||
"type": "rich_text_section", | ||
"elements": [ | ||
{ | ||
"type": "link", | ||
"url": "https://${{ vars.JIRA_DOMAIN }}/browse/" + ticket, | ||
"text": ticket | ||
} | ||
] | ||
}); | ||
}); | ||
console.log("payload", payload); | ||
try { | ||
const slackResponse = await fetch("https://slack.com/api/chat.postMessage", { | ||
method: "POST", | ||
headers: { | ||
"Authorization": "Bearer ${{ secrets.SLACK_API_TOKEN }}", | ||
"Content-Type": "application/json" | ||
}, | ||
body: JSON.stringify(payload) | ||
}); | ||
if (!slackResponse.ok) { | ||
const err = await slackResponse.json(); | ||
throw new Error("Failed to send message: " + JSON.stringify(err)); | ||
} | ||
console.log("Message sent successfully !"); | ||
} catch (error) { | ||
console.error("Request error", error.message); | ||
} | ||
})(); | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,4 +77,7 @@ captures/ | |
report.xml | ||
|
||
# GPG | ||
*.gpg | ||
*.gpg | ||
|
||
# env files | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
stages: | ||
- release | ||
|
||
# Job to get JIRA tickets of the release | ||
get-jira-tickets: | ||
stage: release | ||
image: node:latest | ||
rules: | ||
- if: $CI_COMMIT_TAG | ||
- if: $ONLY_DEPLOY | ||
when: never | ||
script: | ||
- | | ||
node <<EOF | ||
(async () => { | ||
try { | ||
const gitlabResponse = await fetch("${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/merge_requests?state=merged&target_branch=develop&milestone=${CI_COMMIT_TAG}", { | ||
method: "GET", | ||
headers: { | ||
"Private-Token": "$GITLAB_API_TOKEN" | ||
} | ||
}); | ||
if (!gitlabResponse.ok) { | ||
const err = await gitlabResponse.json(); | ||
throw new Error("Failed to send GitLab request: " + JSON.stringify(err)); | ||
} | ||
const mergeRequests = await gitlabResponse.json(); | ||
let tickets = []; | ||
mergeRequests.forEach((mr) => { | ||
const matches = mr.source_branch.match(/EC-\d+/); | ||
if(matches?.length) { | ||
tickets.push(matches[0].toUpperCase()); | ||
} | ||
}); | ||
tickets = [...new Set(tickets)]; | ||
console.log("tickets", tickets); | ||
const payload = { | ||
"event_type": "trigger-artifact-workflow", | ||
"client_payload": { | ||
"tickets": tickets | ||
} | ||
}; | ||
console.log("payload", JSON.stringify(payload)); | ||
const githubResponse = await fetch("https://api.github.com/repos/${GITHUB_ORGANIZATION}/${GITHUB_PROJECT}/dispatches", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer ${GITHUB_TOKEN}", | ||
"User-Agent": "Node.js" | ||
}, | ||
body: JSON.stringify(payload) | ||
}); | ||
if (!githubResponse.ok) { | ||
const err = await githubResponse.json(); | ||
throw new Error("Failed to send GitHub event: " + JSON.stringify(err)); | ||
} | ||
} catch (error) { | ||
throw new Error("Request error: " + error.message); | ||
} | ||
})(); | ||
EOF | ||
# Release note job | ||
release-job: | ||
stage: release | ||
image: registry.gitlab.com/gitlab-org/release-cli:latest | ||
needs: | ||
- get-jira-tickets | ||
variables: | ||
TEMP_CHANGELOG_FILE: 'release_changelog.txt' | ||
rules: | ||
- if: $CI_COMMIT_TAG | ||
- if: $ONLY_DEPLOY | ||
when: never | ||
script: | ||
- | | ||
# Extract changelog part according to tag version | ||
CHANGELOG=$(awk -v version="## $CI_COMMIT_TAG" ' | ||
$0 ~ version {printit=1; next} | ||
printit && /^## / {exit} | ||
printit {print} | ||
' CHANGELOG.md) | ||
{ | ||
echo "# CHANGE LOG" | ||
echo "$CHANGELOG" | ||
} > "$TEMP_CHANGELOG_FILE" | ||
- cat "$TEMP_CHANGELOG_FILE" | ||
release: | ||
tag_name: $CI_COMMIT_TAG | ||
name: Version $CI_COMMIT_TAG | ||
description: '$TEMP_CHANGELOG_FILE' | ||
milestones: | ||
- $CI_COMMIT_TAG |
Oops, something went wrong.