|
| 1 | +name: Open Umbrella Stack PR |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + version: |
| 9 | + description: "Component version (e.g. 4.4.0 or v4.4.0)" |
| 10 | + required: true |
| 11 | + release_notes: |
| 12 | + description: "Optional release notes for PR context" |
| 13 | + required: false |
| 14 | + release_url: |
| 15 | + description: "Optional release URL for PR context" |
| 16 | + required: false |
| 17 | + umbrella_repository: |
| 18 | + description: "Optional override for umbrella repository (org/repo)" |
| 19 | + required: false |
| 20 | + umbrella_base_branch: |
| 21 | + description: "Optional override for umbrella base branch" |
| 22 | + required: false |
| 23 | + stack_file: |
| 24 | + description: "Optional override for stack file path" |
| 25 | + required: false |
| 26 | + |
| 27 | +permissions: |
| 28 | + contents: read |
| 29 | + |
| 30 | +env: |
| 31 | + UMBRELLA_REPOSITORY: FIWARE-TMForum/Business-API-Ecosystem |
| 32 | + UMBRELLA_BASE_BRANCH: master |
| 33 | + UMBRELLA_STACK_FILE: stack.yml |
| 34 | + |
| 35 | +jobs: |
| 36 | + open-umbrella-pr: |
| 37 | + runs-on: ubuntu-latest |
| 38 | + steps: |
| 39 | + - name: Resolve release metadata |
| 40 | + id: meta |
| 41 | + shell: bash |
| 42 | + run: | |
| 43 | + if [[ "${{ github.event_name }}" == "release" ]]; then |
| 44 | + RAW_VERSION="$(jq -r '.release.tag_name // empty' "$GITHUB_EVENT_PATH")" |
| 45 | + RELEASE_NAME="$(jq -r '.release.name // empty' "$GITHUB_EVENT_PATH")" |
| 46 | + RELEASE_URL="$(jq -r '.release.html_url // empty' "$GITHUB_EVENT_PATH")" |
| 47 | + BODY="$(jq -r '.release.body // empty' "$GITHUB_EVENT_PATH")" |
| 48 | + else |
| 49 | + RAW_VERSION="${{ inputs.version }}" |
| 50 | + RELEASE_NAME="${{ inputs.version }}" |
| 51 | + RELEASE_URL="${{ inputs.release_url }}" |
| 52 | + BODY="${{ inputs.release_notes }}" |
| 53 | + fi |
| 54 | +
|
| 55 | + UMBRELLA_REPOSITORY_INPUT="${{ inputs.umbrella_repository }}" |
| 56 | + UMBRELLA_BASE_BRANCH_INPUT="${{ inputs.umbrella_base_branch }}" |
| 57 | + STACK_FILE_INPUT="${{ inputs.stack_file }}" |
| 58 | +
|
| 59 | + UMBRELLA_REPOSITORY="${UMBRELLA_REPOSITORY_INPUT:-${{ env.UMBRELLA_REPOSITORY }}}" |
| 60 | + UMBRELLA_BASE_BRANCH="${UMBRELLA_BASE_BRANCH_INPUT:-${{ env.UMBRELLA_BASE_BRANCH }}}" |
| 61 | + STACK_FILE="${STACK_FILE_INPUT:-${{ env.UMBRELLA_STACK_FILE }}}" |
| 62 | +
|
| 63 | + VERSION="${RAW_VERSION#v}" |
| 64 | + SAFE_VERSION="$(echo "$VERSION" | tr '/ _' '-' | tr -cd '[:alnum:].-')" |
| 65 | + BRANCH_NAME="chore/stack-front-${SAFE_VERSION}" |
| 66 | +
|
| 67 | + if [[ -z "$VERSION" ]]; then |
| 68 | + echo "Version is empty. Verify release tag or workflow_dispatch input." |
| 69 | + exit 1 |
| 70 | + fi |
| 71 | +
|
| 72 | + if [[ -z "$RELEASE_NAME" ]]; then |
| 73 | + RELEASE_NAME="$RAW_VERSION" |
| 74 | + fi |
| 75 | +
|
| 76 | + if [[ -z "$BODY" ]]; then |
| 77 | + BODY="_No release notes provided._" |
| 78 | + fi |
| 79 | +
|
| 80 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 81 | + echo "source_tag=$RAW_VERSION" >> "$GITHUB_OUTPUT" |
| 82 | + echo "release_name=$RELEASE_NAME" >> "$GITHUB_OUTPUT" |
| 83 | + echo "release_url=$RELEASE_URL" >> "$GITHUB_OUTPUT" |
| 84 | + echo "branch_name=$BRANCH_NAME" >> "$GITHUB_OUTPUT" |
| 85 | + echo "umbrella_repository=$UMBRELLA_REPOSITORY" >> "$GITHUB_OUTPUT" |
| 86 | + echo "umbrella_base_branch=$UMBRELLA_BASE_BRANCH" >> "$GITHUB_OUTPUT" |
| 87 | + echo "stack_file=$STACK_FILE" >> "$GITHUB_OUTPUT" |
| 88 | + { |
| 89 | + echo "release_body<<EOF" |
| 90 | + echo "$BODY" |
| 91 | + echo "EOF" |
| 92 | + } >> "$GITHUB_OUTPUT" |
| 93 | +
|
| 94 | + - name: Validate workflow configuration |
| 95 | + shell: bash |
| 96 | + run: | |
| 97 | + if [[ "${{ steps.meta.outputs.umbrella_repository }}" == "your-org/umbrella-repo" ]]; then |
| 98 | + echo "Please set UMBRELLA_REPOSITORY in workflow env or workflow_dispatch input." |
| 99 | + exit 1 |
| 100 | + fi |
| 101 | +
|
| 102 | + if [[ -z "${{ secrets.UMBRELLA_REPO_PAT || secrets.COMPAT_REPO_PAT }}" ]]; then |
| 103 | + echo "Set UMBRELLA_REPO_PAT (or COMPAT_REPO_PAT) with repo write permissions to the umbrella repository." |
| 104 | + exit 1 |
| 105 | + fi |
| 106 | +
|
| 107 | + - name: Checkout umbrella repository |
| 108 | + uses: actions/checkout@v4 |
| 109 | + with: |
| 110 | + repository: ${{ steps.meta.outputs.umbrella_repository }} |
| 111 | + ref: ${{ steps.meta.outputs.umbrella_base_branch }} |
| 112 | + token: ${{ secrets.UMBRELLA_REPO_PAT || secrets.COMPAT_REPO_PAT }} |
| 113 | + path: umbrella |
| 114 | + |
| 115 | + - name: Install yq |
| 116 | + shell: bash |
| 117 | + run: | |
| 118 | + sudo wget -q -O /usr/local/bin/yq \ |
| 119 | + https://github.com/mikefarah/yq/releases/download/v4.44.3/yq_linux_amd64 |
| 120 | + sudo chmod +x /usr/local/bin/yq |
| 121 | +
|
| 122 | + - name: Update stack.yml version |
| 123 | + id: stack |
| 124 | + shell: bash |
| 125 | + run: | |
| 126 | + TARGET_FILE="umbrella/${{ steps.meta.outputs.stack_file }}" |
| 127 | +
|
| 128 | + if [[ ! -f "$TARGET_FILE" ]]; then |
| 129 | + echo "Stack file not found: $TARGET_FILE" |
| 130 | + exit 1 |
| 131 | + fi |
| 132 | +
|
| 133 | + STACK_LENGTH="$(yq e '.stacks | length' "$TARGET_FILE")" |
| 134 | + if [[ ! "$STACK_LENGTH" =~ ^[0-9]+$ || "$STACK_LENGTH" -lt 1 ]]; then |
| 135 | + echo "No stack entries found in $TARGET_FILE" |
| 136 | + exit 1 |
| 137 | + fi |
| 138 | +
|
| 139 | + LAST_INDEX=$((STACK_LENGTH - 1)) |
| 140 | + NEW_STACK_ID="$(date -u +%Y.%m.%d)" |
| 141 | + export NEW_STACK_ID |
| 142 | +
|
| 143 | + yq -i ".stacks = [(.stacks[$LAST_INDEX] | .front = strenv(VERSION) | .id = strenv(NEW_STACK_ID))]" "$TARGET_FILE" |
| 144 | +
|
| 145 | + echo "stack_source_index=$LAST_INDEX" >> "$GITHUB_OUTPUT" |
| 146 | + echo "stack_id=$(yq e '.stacks[0].id' "$TARGET_FILE")" >> "$GITHUB_OUTPUT" |
| 147 | + echo "stack_description=$(yq e '.stacks[0].description' "$TARGET_FILE")" >> "$GITHUB_OUTPUT" |
| 148 | + echo "proxy_branch=$(yq e '.stacks[0].proxy' "$TARGET_FILE")" >> "$GITHUB_OUTPUT" |
| 149 | + echo "charging_branch=$(yq e '.stacks[0].charging' "$TARGET_FILE")" >> "$GITHUB_OUTPUT" |
| 150 | + echo "frontend_branch=$(yq e '.stacks[0].front' "$TARGET_FILE")" >> "$GITHUB_OUTPUT" |
| 151 | + echo "tm_version=$(yq e '.stacks[0].apis' "$TARGET_FILE")" >> "$GITHUB_OUTPUT" |
| 152 | + env: |
| 153 | + VERSION: ${{ steps.meta.outputs.version }} |
| 154 | + |
| 155 | + - name: Build PR body |
| 156 | + id: prbody |
| 157 | + shell: bash |
| 158 | + run: | |
| 159 | + PR_BODY_FILE="${RUNNER_TEMP}/umbrella-stack-pr-body.md" |
| 160 | + cat > "$PR_BODY_FILE" <<EOF |
| 161 | + This PR was created automatically from a release in \`${{ github.repository }}\`. |
| 162 | +
|
| 163 | + ## Stack update |
| 164 | + - Source entry: last stack entry (index \`${{ steps.stack.outputs.stack_source_index }}\`) |
| 165 | + - Stack id: \`${{ steps.stack.outputs.stack_id }}\` |
| 166 | + - Stack description: \`${{ steps.stack.outputs.stack_description }}\` |
| 167 | + - New version: \`${{ steps.meta.outputs.version }}\` |
| 168 | + - Updated file: \`${{ steps.meta.outputs.stack_file }}\` |
| 169 | + - Updated field: \`stacks[last].front\` |
| 170 | + - Array rewrite: \`stacks\` now contains only the new entry |
| 171 | +
|
| 172 | + ## System testing setup |
| 173 | + SYSTEM_TESTING: ACTIVATE |
| 174 | + PROXY_BRANCH: ${{ steps.stack.outputs.proxy_branch }} |
| 175 | + CHARGING_BRANCH: ${{ steps.stack.outputs.charging_branch }} |
| 176 | + FRONTEND_BRANCH: ${{ steps.stack.outputs.frontend_branch }} |
| 177 | + TM_VERSION: ${{ steps.stack.outputs.tm_version }} |
| 178 | +
|
| 179 | + ## Source release context |
| 180 | + - Source repository: \`${{ github.repository }}\` |
| 181 | + - Source release: \`${{ steps.meta.outputs.release_name }}\` |
| 182 | + - Source tag/input: \`${{ steps.meta.outputs.source_tag }}\` |
| 183 | + - Source release URL: ${{ steps.meta.outputs.release_url }} |
| 184 | + - Triggered by: \`${{ github.actor }}\` |
| 185 | + - Trigger run: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 186 | +
|
| 187 | + ## Release notes |
| 188 | + ${{ steps.meta.outputs.release_body }} |
| 189 | + EOF |
| 190 | + echo "file=$PR_BODY_FILE" >> "$GITHUB_OUTPUT" |
| 191 | +
|
| 192 | + - name: Create pull request in umbrella repository |
| 193 | + id: cpr |
| 194 | + uses: peter-evans/create-pull-request@v7 |
| 195 | + with: |
| 196 | + path: umbrella |
| 197 | + token: ${{ secrets.UMBRELLA_REPO_PAT || secrets.COMPAT_REPO_PAT }} |
| 198 | + branch: ${{ steps.meta.outputs.branch_name }} |
| 199 | + base: ${{ steps.meta.outputs.umbrella_base_branch }} |
| 200 | + title: >- |
| 201 | + chore(stack): bump front to |
| 202 | + ${{ steps.meta.outputs.version }} |
| 203 | + commit-message: >- |
| 204 | + chore(stack): bump front to |
| 205 | + ${{ steps.meta.outputs.version }} |
| 206 | + body-path: ${{ steps.prbody.outputs.file }} |
| 207 | + labels: | |
| 208 | + automated |
| 209 | + compatibility |
| 210 | + delete-branch: true |
| 211 | + |
| 212 | + - name: Workflow summary |
| 213 | + shell: bash |
| 214 | + run: | |
| 215 | + if [[ -n "${{ steps.cpr.outputs.pull-request-url }}" ]]; then |
| 216 | + echo "Created PR: ${{ steps.cpr.outputs.pull-request-url }}" |
| 217 | + else |
| 218 | + echo "No PR created (likely no changes detected in stack file)." |
| 219 | + fi |
0 commit comments