Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .github/config/repos-to-release.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/gridsuite/ci-cd-test
58 changes: 54 additions & 4 deletions .github/workflows/dispatch-release.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,61 @@
name: Prepare release
name: Dispatch release

on:
workflow_dispatch:
inputs:
release-version:
description: Release version (vX.X)
required: true
type: string
branch-name:
description: Branch to release (prepare-release-X.X)
required: true
type: string
pat-token:
description: PAT token (with workflow permissions)

jobs:
say-hello:
dispatch-release:
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Echo message
run: echo "Hello"
- name: Checkout aggregator repository
uses: actions/checkout@v4
with:
submodules: false
ref: release-workflow

- name: Load repo list from file or input
id: load_repos
run: |
if [[ -z "${{ github.event.inputs.repos_to_release }}" ]]; then
echo "ℹ️ No user input → load .github/config/repos-to-release.txt"
list="$(cat .github/config/repos-to-release.txt)"
else
echo "ℹ️ Input found → load user input"
list="${{ github.event.inputs.repos_to_release }}"
fi
echo "list<<EOF" >> $GITHUB_OUTPUT
echo "$list" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

- name: Create tags and trigger release workflows
run: |
while read url; do

version=${{github.event.inputs.release-version}}
branch_name=${{github.event.inputs.branch-name}}

owner=$(echo "$url" | cut -d/ -f4)
repo=$(echo "$url" | cut -d/ -f5 | sed 's/\.git$//')

gh api repos/$owner/$repo/actions/workflows/release.yml/dispatches \
-f ref=main \
-f inputs[releaseVersion]="$version" \
-f inputs[gitReference]="$branch_name"

done <<< "${{ steps.load_repos.outputs.list }}"
env:
GH_TOKEN: ${{ github.event.inputs.pat-token }}
108 changes: 105 additions & 3 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,112 @@ name: Prepare release

on:
workflow_dispatch:
inputs:
repos_to_release:
description: "Manual list of repositories to release (.github/config/repos-to-release.txt content if left empty)"
default: ""
required: false
target_date:
description: "Date of last commit to inlude (ISO 8601, ex: 2024-09-13T23:59:59Z - default : last friday 23:59:59)."
required: false
release-version:
description: "Version for new tag (ex: 2.8)"
required: true
secrets:
VERSIONBUMP_GHAPP_PRIVATE_KEY:
required: true

jobs:
say-hello:
prepare-release:
runs-on: ubuntu-latest
steps:
- name: Echo message
run: echo "Hello"
- name: Checkout aggregator repository
uses: actions/checkout@v4
with:
submodules: false
ref: release-workflow

- uses: actions/create-github-app-token@21cfef2b496dd8ef5b904c159339626a10ad380e # v1 v1.11.6
id: app-token
name: Generate app token
with:
app-id: ${{ vars.GRIDSUITE_ACTIONS_APPID }}
private-key: ${{ secrets.VERSIONBUMP_GHAPP_PRIVATE_KEY }}
owner: gridsuite

- name: Get GitHub App User ID
id: get-user-id
run: |
echo $(gh api "/users/${RUNGHA_APP_SLUG}[bot]")
echo "user-id=$(gh api "/users/${RUNGHA_APP_SLUG}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
RUNGHA_APP_SLUG: ${{ steps.app-token.outputs.app-slug }} # just for defense against script injection

- name: Setup git user
run: |
git config --global user.name "${RUNGHA_APP_SLUG}[bot]"
git config --global user.email "${RUNGHA_USER_ID}+${RUNGHA_APP_SLUG}[bot]@users.noreply.github.com"
env:
RUNGHA_APP_SLUG: ${{ steps.app-token.outputs.app-slug }} # just for defense against script injection
RUNGHA_USER_ID: ${{ steps.get-user-id.outputs.user-id }} # just for defense against script injection

- name: Load repo list from file or input
id: load_repos
run: |
if [[ -z "${{ github.event.inputs.repos_to_release }}" ]]; then
echo "ℹ️ No user input → load .github/config/repos-to-release.txt"
list="$(cat .github/config/repos-to-release.txt)"
else
echo "ℹ️ Input found → load user input"
list="${{ github.event.inputs.repos_to_release }}"
fi
echo "list<<EOF" >> $GITHUB_OUTPUT
echo "$list" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

- name: Extract last commit date (last friday 23:59 UTC if left empty)
id: load_date
run: |
if [ -z "${{ github.event.inputs.target_date }}" ]; then
date_value=$(date -u -d "last friday 23:59" +"%Y-%m-%dT%H:%M:%SZ")
else
date_value="${{ github.event.inputs.target_date }}"
fi
echo "date_value=$date_value" >> $GITHUB_OUTPUT
echo "This limit date will be used : $date_value"

- name: Lister les SHAs des commits
run: |
mkdir public_repos
cd public_repos

while read url; do
url_with_token="${url/https:\/\/github.com/https:\/\/x-access-token:${TOKEN}@github.com}"
git clone "$url_with_token"
folder=$(basename "$url" .git)
cd $folder
commit_date="${{ steps.load_date.outputs.date_value }}"
commit_hash=$(git rev-list -n 1 --before="$commit_date" main)
git checkout $commit_hash

branch_name="prepare-release-${{github.event.inputs.release-version}}"
# Check if *branch_name* already exists
if git ls-remote --exit-code origin "refs/heads/$branch_name"; then
echo "❌ Warning for $folder: Branch $branch_name already exists"
exit 1
fi
git checkout -b "$branch_name"

if ! git push origin "$branch_name"; then
echo "❌ Error for $folder: Failed to push $branch_name"
exit 1
fi

commit_message=$(git log -1 --pretty=%s | cut -c1-50)

echo "✅ $folder : $branch_name branch created → $commit_hash | $commit_message"
cd - > /dev/null
done <<< "${{ steps.load_repos.outputs.list }}"
env:
TOKEN: ${{ steps.app-token.outputs.token }}
Loading