Skip to content

fix: Update wording for In-Page advanced feature #147

fix: Update wording for In-Page advanced feature

fix: Update wording for In-Page advanced feature #147

Workflow file for this run

# This workflow is triggered when a pull request is merged and the label 'release' is present.
# It fetches the last draft release, updates it to a non-draft release and sends a Slack message with the release notes.
name: Publish Release
on:
pull_request:
types:
- closed
jobs:
release:
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release')
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Install taskfile.dev
uses: arduino/setup-task@v2
with:
version: 3.x
repo-token: ${{ github.token }}
- name: Create release zip file
shell: bash
run: |
task dist
- name: Fetch last draft release
id: fetch-release-draft
shell: bash
run: |
# Call Github releases API and filter draft releases
DRAFT_RELEASE=$(curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}" \
https://api.github.com/repos/${{ github.repository }}/releases | \
jq 'map(select(.draft == true))' \
)
# We should find exactly 1 draft release to be published
if [[ $(echo $DRAFT_RELEASE | jq 'length') -eq 1 ]]
then
echo "Draft release found"
DRAFT_RELEASE=$(echo $DRAFT_RELEASE | jq first)
else
# Fail if more than 1 draft release is found
if [[ $(echo $DRAFT_RELEASE | jq 'length') -gt 1 ]]
then
echo "Unable to publish the release: More than one draft is found"
exit 1
fi
# If no draft release is found, maybe the draft has been manually published by error
# prior to the workflow execution
echo "No draft release found, checking for the latest release..."
LATEST_RELEASE=$(curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}" \
https://api.github.com/repos/${{ github.repository }}/releases/latest
)
# Compare the latest release version with the version in the branch name of the PR
# (which should be release/<version> or hotfix/<version>)
# If they match, we consider the latest release as the draft release
VERSION_FROM_LATEST_RELEASE=$(echo $LATEST_RELEASE | jq -r '.name')
echo "Latest release version: $VERSION_FROM_LATEST_RELEASE"
VERSION_FROM_PR_BRANCH_NAME=$(echo ${{ github.event.pull_request.head.ref }} | sed -E 's/(release|hotfix)\///')
echo "Version found from PR branch name: $VERSION_FROM_PR_BRANCH_NAME"
if [[ "$VERSION_FROM_LATEST_RELEASE" == "$VERSION_FROM_PR_BRANCH_NAME" ]]
then
echo "Version from the latest release matches with the version found in the release/hotfix PR branch name"
DRAFT_RELEASE=$LATEST_RELEASE
else
echo "Unable to publish the release: Latest release does not match with the version found in the PR branch name"
exit 1
fi
fi
# Retrieve name, id and body of the draft release
NAME=$(echo $DRAFT_RELEASE | jq -r '.name')
ID=$(echo $DRAFT_RELEASE | jq '.id')
BODY=$(echo $DRAFT_RELEASE | jq -r '.body')
# Add URLs to GitHub pull requests
PULL_REQUEST_URL_START=${{ github.server_url }}/${{ github.repository }}/pull/
ESCAPED_PULL_REQUEST_URL_START=$(printf '%s\n' "$PULL_REQUEST_URL_START" | sed -e 's/[\/&]/\\&/g')
BODY=$(echo -e "$BODY" | sed -E "s/#([0-9]+)/[#\1](${ESCAPED_PULL_REQUEST_URL_START}\1)/g")
# Add URLs to GitHub profiles
PROFILE_URL_START=${{ github.server_url }}/
ESCAPED_PROFILE_URL_START=$(printf '%s\n' "$PROFILE_URL_START" | sed -e 's/[\/&]/\\&/g')
BODY=$(echo -e "$BODY" | sed -E "s/@([[:alnum:]-]+)/[@\1](${ESCAPED_PROFILE_URL_START}\1)/g")
# Write the output variables
echo "name=$NAME" >> $GITHUB_OUTPUT
echo "id=$ID" >> $GITHUB_OUTPUT
echo "body<<EOF" >> $GITHUB_OUTPUT
echo -e "$BODY" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Add zip file to the release assets
shell: bash
run: |
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}" \
-H "Content-Type: application/zip" \
-T "dist/alma.zip" \
https://uploads.github.com/repos/${{ github.repository }}/releases/${{ steps.fetch-release-draft.outputs.id }}/assets?name=alma.zip
- name: Publish Github release
uses: actions/github-script@v7
with:
# target_commitish is set to refs/heads/develop by release-drafter as we need to retrieve pull requests merged into develop
# We need to override it to refs/heads/main to point to the last commit of main branch instead of develop branch
script: |
const { owner, repo } = context.repo;
await github.rest.repos.updateRelease({
owner,
repo,
release_id: "${{ steps.fetch-release-draft.outputs.id }}",
draft: false,
make_latest: true,
tag_name: "${{ steps.fetch-release-draft.outputs.name }}",
target_commitish: "refs/heads/main"
});
- name: Format release notes for Slack
uses: LoveToKnow/[email protected]
id: slack-markdown-release-notes
with:
text: |
:tada: New publication of PrestaShop Alma module, **[${{ steps.fetch-release-draft.outputs.name }}](https://github.com/${{ github.repository }}/releases/tag/${{ steps.fetch-release-draft.outputs.name }})**:
${{ steps.fetch-release-draft.outputs.body }}
:warning: This release will be available on PrestaShop marketplace in a few hours
cc <@france.berut> <@khadija.cherif>
- name: Send changelog to Slack
uses: slackapi/[email protected]
with:
channel-id: CR9C57YM6
slack-message: ${{ steps.slack-markdown-release-notes.outputs.text }}
payload: |
{
"username": "${{ github.event.sender.login }}",
"icon_url": "${{ github.event.sender.avatar_url }}"
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_RELEASE_CHANGELOG_BOT_TOKEN }}