Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ci): replace job conditional by dedicated step #1169

Merged
merged 5 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions .github/actions/release/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ inputs:
github_ref_name:
description: "Github ref name"
required: true
jira_api_token:
description: "Token to authenticate to Jira"
required: true
jira_user_email:
description: "Email linked to token"
required: true
jira_project_id:
description: "Jira project id to create release"
required: true
jira_webhook_url:
description: "Jira release webhook"
required: true
jira_user_email:
description: "Jira user email"
required: true
jira_api_token:
description: "Jira api token"
required: true

runs:
using: "composite"
Expand All @@ -26,7 +26,7 @@ runs:
- name: Get released versions for components
run: |
set -eu
COMPONENTS_RELEASED=()

COMPONENTS_OSS=("centreon-awie" "centreon-dsm" "centreon-gorgone" "centreon-ha" "centreon-open-tickets" "centreon-web")
COMPONENTS_MODULES=("centreon-anomaly-detection" "centreon-autodiscovery" "centreon-bam" "centreon-cloud-business-extensions" "centreon-cloud-extensions" "centreon-it-edition-extensions" "centreon-license-manager" "centreon-map" "centreon-mbi" "centreon-pp-manager")
COMPONENTS_COLLECT=("centreon-collect")
Expand All @@ -53,12 +53,11 @@ runs:
PREVIOUS_STABLE_TAGS+=($(git tag -l --sort=-version:refname "$component-$CURRENT_STABLE_BRANCH_MAJOR_VERSION*" | head -n 1))
# New stable tags array
NEW_STABLE_TAGS+=("$component-$MAJOR_VERSION.$MINOR_VERSION")

done
echo "Previous releases were: ${PREVIOUS_STABLE_TAGS[*]}"
echo "New releases are: ${NEW_STABLE_TAGS[*]}"

# Check that NEW_STABLE_TAGS are fully different from PREVIOUS_STABLE_TAGS
# TODO: Check that NEW_STABLE_TAGS are fully different from PREVIOUS_STABLE_TAGS
# re use the part from check version ??
# or use the check-version action after turning this release action into a real workflow ?

Expand All @@ -81,7 +80,7 @@ runs:
if [ -z $(git tag --list "$TAG" | head -n 1) ]; then
git tag -a "$TAG" -m "$TAG"
git push --follow-tags
echo "::notice::Tagging branch with $TAG."
echo "::notice::Tagging stable branch with $TAG."
else
echo "::error::Release tag $TAG already exists, exiting."
exit 1
Expand All @@ -95,20 +94,20 @@ runs:
echo "Installing GH CLI."
if ! command -v gh &> /dev/null; then
echo "Installing GH CLI."
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
type -p curl >/dev/null || (sudo apt-get update && sudo apt-get install curl -y)
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh -y
sudo apt-get update
sudo apt-get install gh -y
else
echo "GH CLI is already installed."
fi

# Create GITHUB release for each release components
echo "Creating GITHUB releases."
for TAG in ${NEW_STABLE_TAGS[@]}; do
echo "::notice::Creating release with title $TAG for tag $TAG."
echo "Creating GITHUB release with title $TAG for tag $TAG."
gh release create $TAG --target "${{ inputs.github_ref_name }} --title "$TAG" --verify-tag
done
shell: bash
Expand All @@ -117,6 +116,10 @@ runs:
run: |
set -eu

# Call JIRA to provide new jira versions to create
# Webhook url
JIRA_INCOMING_WEBHOOK="${{ inputs.jira_webhook_url }}"

# Rebuild NEW_STABLE_TAGS as an array
for i in ${NEW_STABLE_TAGS[@]}; do
NEW_RELEASE_TAGS+=("$i")
Expand Down Expand Up @@ -179,7 +182,7 @@ runs:
# DEBUG
echo "JSON_TAGS: \r\n$JSON_TAGS"
echo "JSON_VERSION_INFO: $JSON_VERSION_INFO"
echo "Sending to JIRA AUTOMATION: \r\n$RELEASE_JSON"
echo "Sending to JIRA automation: \r\n$RELEASE_JSON"

# Call jira webhook to trigger the communication workflow
# and provide versions data for communication
Expand Down
17 changes: 15 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,22 @@ on:

jobs:
release:
if: github.event.pull_request.merged == true && (github.base_ref == 'master' || github.base_ref == '[2-9][0-9].[0-9][0-9].x')
if: ${{ github.event.pull_request.merged == true }}
runs-on: ubuntu-22.04
steps:
- name: Check base_ref
run: |
set -eu
# Check if github.base_ref is either master or any of the supported version ones
# This must never run on any other than master and supported version base_ref
if [[ "${{ github.base_ref }}" == 'master' || "${{ github.base_ref }}" =~ ^[2-9][0-9].[0-9][0-9].x ]];then
echo "[DEBUG] base_ref is valid: ${{ github.base_ref }}"
else
echo "::error::base_ref is not valid (${{ github.base_ref }}), exiting."
exit 1
fi
shell: bash

- name: Checkout sources
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
Expand All @@ -34,6 +47,6 @@ jobs:
with:
github_ref_name: ${{ github.head_ref || github.ref_name }}
jira_project_id: ${{ secrets.JIRA_PROJECT_ID }}
jira_webhook_url: ${{ secrets.JIRA_RELEASE_WEBHOOK }}
jira_user_email: ${{ secrets.XRAY_JIRA_USER_EMAIL }}
jira_api_token: ${{ secrets.XRAY_JIRA_TOKEN }}
jira_webhook_url: ${{ secrets.JIRA_RELEASE_WEBHOOK }}