Skip to content

Commit

Permalink
Merge branch 'release/2.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
thibautgdt committed Dec 3, 2024
2 parents b875a30 + 93cf6b8 commit 12995f9
Show file tree
Hide file tree
Showing 17 changed files with 381 additions and 134 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
environment: stage
steps:
- name: Checkout Repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Ruby
uses: actions/setup-ruby@v1
Expand Down Expand Up @@ -41,7 +41,7 @@ jobs:
API_DATA_URL_STAGE: ${{ secrets.API_DATA_URL_STAGE }}
steps:
- name: Checkout Repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Ruby
uses: actions/setup-ruby@v1
Expand All @@ -55,7 +55,7 @@ jobs:
run: fastlane BuildDemo

- name: Save .apk in artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: example-release.apk
path: example/build/outputs/apk/release/example-release.apk
Expand All @@ -68,7 +68,7 @@ jobs:
APPCENTER_TOKEN: ${{ secrets.APPCENTER_TOKEN }}
steps:
- name: Checkout Repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Ruby
uses: actions/setup-ruby@v1
Expand All @@ -79,7 +79,7 @@ jobs:
run: gem install bundler && bundle install

- name: Download APK from previous job
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: example-release.apk

Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/info-release.yml
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
111 changes: 111 additions & 0 deletions .github/workflows/slack-message.yml
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,7 @@ captures/
report.xml

# GPG
*.gpg
*.gpg

# env files
.env
103 changes: 103 additions & 0 deletions .gitlab-ci.yml
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
Loading

0 comments on commit 12995f9

Please sign in to comment.