crucible-release #66
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: crucible-release | |
on: # yamllint disable-line rule:truthy | |
schedule: | |
# Runs every 3 months (1st day of the quarter) | |
- cron: "0 0 1 */3 *" | |
workflow_dispatch: | |
inputs: | |
dry_run: | |
required: false | |
type: boolean | |
description: Do NOT push/delete tag to/from the repositories | |
default: false | |
custom_tag: | |
required: false | |
type: string | |
description: Custom tag to push/delete | |
default: '' | |
action: | |
required: true | |
type: choice | |
options: | |
- push | |
- delete | |
description: Action to perform with the custom-tag (push or delete) | |
default: 'push' | |
force_push: | |
required: false | |
type: boolean | |
description: FORCE push (override tag) | |
default: false | |
jobs: | |
release-tag: | |
runs-on: [ self-hosted, workflow-overhead ] | |
timeout-minutes: 10 | |
outputs: | |
tag: ${{ steps.gen-release-tag.outputs.tag }} | |
repos: ${{ steps.get-repos.outputs.repos }} | |
steps: | |
- name: Generate release tag | |
id: gen-release-tag | |
run: | | |
if [ "${{ inputs.custom_tag }}" == "" ]; then | |
year="$(date +%Y)" | |
month="$(date +%m)" | |
month=${month#0} | |
quarter="$(((month-1)/3+1))" | |
echo "tag=$year.$quarter" >> $GITHUB_OUTPUT | |
else | |
echo "tag=${{ inputs.custom_tag }}" >> $GITHUB_OUTPUT | |
fi | |
- name: Display params | |
id: get-params | |
env: | |
TAG: ${{ needs.release-tag.outputs.tag }} | |
DRY_RUN: ${{ inputs.dry_run }} | |
CUSTOM_TAG: ${{ inputs.custom_tag }} | |
ACTION: ${{ inputs.action }} | |
GITHUB_EVENT: ${{ github.event_name }} | |
FORCE_PUSH: ${{ inputs.force_push }} | |
run: | | |
echo "tag=$TAG" | |
echo "dry_run=$DRY_RUN" | |
echo "custom_tag=$CUSTOM_TAG" | |
echo "action=$ACTION" | |
echo "github_event=$GITHUB_EVENT" | |
echo "force_push=$FORCE_PUSH" | |
- name: Generate token | |
id: generate-token | |
uses: actions/create-github-app-token@v1 | |
with: | |
app-id: ${{ vars.APP_ID__TAG_CRUCIBLE_RELEASE }} | |
private-key: ${{ secrets.PRIVATE_KEY__TAG_CRUCIBLE_RELEASE }} | |
owner: ${{ github.repository_owner }} | |
- name: checkout crucible default | |
uses: actions/checkout@v4 | |
with: | |
repository: perftool-incubator/crucible | |
ref: master | |
path: crucible | |
set-safe-directory: false | |
fetch-tags: true | |
token: ${{ steps.generate-token.outputs.token }} | |
- name: push/delete tag to/from the crucible repo | |
if: ${{ inputs.dry_run == false }} | |
env: | |
TAG: ${{ steps.gen-release-tag.outputs.tag }} | |
run: | | |
cd $GITHUB_WORKSPACE | |
cd crucible | |
echo "Fetching remote heads/tags..." | |
git fetch --prune --prune-tags | |
echo "Tags:" | |
git ls-remote --tags origin | |
echo "Local Tags:" | |
git tag | |
echo "Branches:" | |
git ls-remote --heads origin | |
echo "Local Branches:" | |
git branch | |
if [ "${{ inputs.action }}" == "push" ]; then | |
ARGS="" | |
if [ "${{ inputs.force_push }}" == "true" ]; then | |
ARGS="--force" | |
fi | |
git checkout -B $TAG | |
git push origin heads/$TAG $ARGS #branch | |
git tag $TAG $ARGS | |
git push origin tags/$TAG $ARGS #tag | |
elif [ "${{ inputs.action }}" == "delete" ]; then | |
if [ "${{ inputs.force_push }}" == "true" ]; then | |
git push --delete origin tags/$TAG || true #tag | |
git push --delete origin heads/$TAG || true #branch | |
else | |
git push --delete origin tags/$TAG #tag | |
git push --delete origin heads/$TAG #branch | |
fi | |
fi | |
echo "Tags:" | |
git ls-remote --tags origin | |
- name: Get the list of sub-projects | |
id: get-repos | |
run: | | |
cd $GITHUB_WORKSPACE | |
cd crucible/config | |
# get 3rd column (repo URL) without the starting '/' (remove first char), | |
# so repo urls /a /b /c are extracted to a b c | |
# and add to a bash array ( a b c ) | |
projects=( $(jq -r '.official[] | select(.name != "crucible") | .repository | sub(".*\/"; "")' repos.json) ) | |
# builtin implict join array "a","b","c" (double quotes for a valid json) | |
printf -v list '"%s",' "${projects[@]}" | |
# convert to a comma separated list ["a","b","c"] | |
echo "repos=[${list%,}]" >> $GITHUB_OUTPUT | |
- name: Display sub-projects repos list | |
id: display-repos | |
env: | |
REPOS: ${{ steps.get-repos.outputs.repos }} | |
run: echo "$REPOS" | |
projects-tag: | |
runs-on: [ self-hosted, workflow-overhead ] | |
timeout-minutes: 10 | |
needs: | |
- release-tag | |
strategy: | |
matrix: | |
repository: ${{ fromJSON(needs.release-tag.outputs.repos) }} | |
steps: | |
- name: Display sub-project repository name | |
run: | | |
echo "repository=${{ matrix.repository }}" | |
- name: Generate token | |
id: generate-token | |
uses: actions/create-github-app-token@v1 | |
with: | |
app-id: ${{ vars.APP_ID__TAG_CRUCIBLE_RELEASE }} | |
private-key: ${{ secrets.PRIVATE_KEY__TAG_CRUCIBLE_RELEASE }} | |
owner: ${{ github.repository_owner }} | |
- name: checkout sub-project repository | |
uses: actions/checkout@v4 | |
with: | |
repository: perftool-incubator/${{ matrix.repository }} | |
path: ${{ matrix.repository }} | |
set-safe-directory: false | |
fetch-tags: true | |
token: ${{ steps.generate-token.outputs.token }} | |
- name: push/delete release tag | |
if: ${{ inputs.dry_run == false }} | |
env: | |
TAG: ${{ needs.release-tag.outputs.tag }} | |
run: | | |
cd $GITHUB_WORKSPACE | |
cd ${{ matrix.repository }} | |
echo "Fetching remote heads/tags..." | |
git fetch --prune --prune-tags | |
echo "Tags:" | |
git ls-remote --tags origin | |
echo "Local Tags:" | |
git tag | |
echo "Branches:" | |
git ls-remote --heads origin | |
echo "Local Branches:" | |
git branch | |
if [ "${{ inputs.action }}" == "push" ]; then | |
ARGS="" | |
if [ "${{ inputs.force_push }}" == "true" ]; then | |
ARGS="--force" | |
fi | |
git checkout -B $TAG | |
git push origin heads/$TAG $ARGS #branch | |
git tag $TAG $ARGS | |
git push origin tags/$TAG $ARGS #tag | |
elif [ "${{ inputs.action }}" == "delete" ]; then | |
if [ "${{ inputs.force_push }}" == "true" ]; then | |
git push --delete origin tags/$TAG || true #tag | |
git push --delete origin heads/$TAG || true #branch | |
else | |
git push --delete origin tags/$TAG #tag | |
git push --delete origin heads/$TAG #branch | |
fi | |
fi | |
echo "Tags:" | |
git ls-remote --tags origin |