Skip to content

Prepare release

Prepare release #16

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: v2.8.0)"
required: true
secrets:
VERSIONBUMP_GHAPP_PRIVATE_KEY:
required: true
jobs:
prepare-release:
runs-on: ubuntu-latest
steps:
- 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 }}
- name: Get GitHub App User ID
id: get-user-id
run: 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"
fi
git checkout -b "$branch_name"
if ! git push origin "$branch_name"; then
echo "❌ Error for $folder: Failed to push $branch_name"
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 }}