From 824a0adef4f7d4a2092063adc2afb5d581a3458e Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Mon, 30 Nov 2026 13:31:15 -0500 Subject: [PATCH] Part nasa/cFS#1205, add version update to snapshot Enhances the snapshot workflow with a version number update --- .github/workflows/snapshot-bundle.yml | 88 ------------------- .../workflows/snapshot-module-reusable.yml | 82 ++++++++++++++++- 2 files changed, 81 insertions(+), 89 deletions(-) delete mode 100644 .github/workflows/snapshot-bundle.yml diff --git a/.github/workflows/snapshot-bundle.yml b/.github/workflows/snapshot-bundle.yml deleted file mode 100644 index 46852988b..000000000 --- a/.github/workflows/snapshot-bundle.yml +++ /dev/null @@ -1,88 +0,0 @@ -name: Snapshot CFS bundle - -# Controls when the action will run. -on: - workflow_dispatch: - inputs: - base-branch: - description: 'The base branch to merge into (main)' - type: string - required: false - default: '' - ic-branch: - description: 'The temporary integration branch to create (ic)' - type: string - required: false - default: '' - dev-branch: - description: 'The branch to pull in (dev)' - type: string - required: false - default: '' - pr-label: - description: 'The label(s) to apply to the generated PR' - type: string - required: false - default: 'continuous-integration' - -permissions: - issues: write - contents: write - pull-requests: write - actions: write - -env: - BASE_BRANCH: ${{ inputs.base-branch || 'main' }} - DEV_BRANCH: ${{ inputs.dev-branch || github.event.repository.default_branch }} - PR_LABEL: ${{ inputs.pr-label }} - GH_REPO: ${{ github.repository }} - GH_HOST: github.com - GH_TOKEN: ${{ secrets.GH_PAT || github.token }} - -jobs: - snapshot-submodules: - name: Snapshot CFS submodules - runs-on: ubuntu-latest - - steps: - - name: Determine IC branch - env: - IC_BRANCH_IN: ${{ inputs.ic-branch }} - run: | - DATE_TAG=$(date +%Y%m%d) - if [ -z "${IC_BRANCH_IN}" ] - then - IC_BRANCH=ic-${DATE_TAG} - else - IC_BRANCH=${IC_BRANCH_IN} - fi - echo "IC_BRANCH=${IC_BRANCH}" >> ${GITHUB_ENV} - echo "DATE_TAG=${DATE_TAG}" >> ${GITHUB_ENV} - - - name: Checkout bundle - uses: actions/checkout@v6 - with: - repository: ${{ github.repository }} - submodules: false - ref: ${{ env.BASE_BRANCH }} - token: ${{ env.GH_TOKEN }} - - - name: Trigger snapshot workflow in all submodules - run: | - sed -e 's/\s*//g' .gitmodules | awk -e 'BEGIN { FS="="; } $1 == "url" { print $2 }' | while read url - do - GH_REPO=${url##*${GH_HOST}/} - GH_REPO=${GH_REPO%.git} - echo GH_REPO=${GH_REPO} - gh workflow run snapshot-module.yml -R "${GH_REPO}" --ref "${DEV_BRANCH}" -f "ic-branch=${IC_BRANCH}" -f "base-branch=${BASE_BRANCH}" -f "dev-branch=${DEV_BRANCH}" -f "pr-label=${PR_LABEL}" - done - - # Kick off the update bundle workflow. This needs to have all the workflows in the previous step - # done before this will work. If this fails due to a missing branch because a workflow had not - # completed yet, it can be easily re-run via the GUI. - - name: Trigger update workflow in bundle - env: - GH_REPO: ${{ github.repository }} - run: | - echo "Delay while submodule workflows complete" && sleep 60 - gh workflow run update-bundle.yml -R "${GH_REPO}" --ref "${DEV_BRANCH}" -f "base-branch=${BASE_BRANCH}" -f "submodule-branch=${IC_BRANCH}" diff --git a/.github/workflows/snapshot-module-reusable.yml b/.github/workflows/snapshot-module-reusable.yml index c6cbaf14b..7a747de4a 100644 --- a/.github/workflows/snapshot-module-reusable.yml +++ b/.github/workflows/snapshot-module-reusable.yml @@ -24,6 +24,11 @@ on: type: string required: false default: '' + version-numbers: + description: 'The pending version/tag info, as a JSON object' + type: string + required: false + default: '{}' permissions: issues: write @@ -38,6 +43,11 @@ env: GH_REPO: ${{ github.repository }} GH_HOST: github.com GH_TOKEN: ${{ secrets.GH_PAT || github.token }} + BASELINE: ${{ fromJSON(inputs.version-numbers).baseline }} + MAJOR_VERSION: ${{ fromJSON(inputs.version-numbers).major }} + MINOR_VERSION: ${{ fromJSON(inputs.version-numbers).minor }} + REVISION: ${{ fromJSON(inputs.version-numbers).rev }} + BUILD_NUMBER: ${{ fromJSON(inputs.version-numbers).build }} jobs: snapshot-module: @@ -92,6 +102,60 @@ jobs: # There must not be conflicts, if there are, then this cannot be done automatically. git merge --no-ff -F ${RUNNER_TEMP}/commit-msg.txt ${DEV_BRANCH} + - name: Find version header file(s) + run: > + find . -type f -name '*version.h' | + grep -v 'ut-stubs' | + tee "${RUNNER_TEMP}/version-files.list" + + - name: Update Baseline + if: env.BASELINE != '' + run: > + cat "${RUNNER_TEMP}/version-files.list" | + xargs -r sed -i -r -e "s/^(#define \S+_BASELINE\s+).*$/\1\"${BASELINE}\"/" + + - name: Update Major Version + if: env.MAJOR_VERSION != '' + run: > + cat "${RUNNER_TEMP}/version-files.list" | + xargs -r sed -i -r -e "s/^(#define \S+_MAJOR_VERSION\s+).*$/\1${MAJOR_VERSION}/" + + - name: Update Minor Version + if: env.MINOR_VERSION != '' + run: > + cat "${RUNNER_TEMP}/version-files.list" | + xargs -r sed -i -r -e "s/^(#define \S+_MINOR_VERSION\s+).*$/\1${MINOR_VERSION}/" + + - name: Update Revision + if: env.REVISION != '' + run: > + cat "${RUNNER_TEMP}/version-files.list" | + xargs -r sed -i -r -e "s/^(#define \S+_REVISION\s+).*$/\1${REVISION}/" + + - name: Update Build Number + if: env.BUILD_NUMBER != '' + run: > + cat "${RUNNER_TEMP}/version-files.list" | + xargs -r sed -i -r -e "s/^(#define \S+_BUILD_NUMBER\s+).*$/\1${BUILD_NUMBER}/" + + - name: Check for changes + if: inputs.version-numbers != '' + env: + VERSION_NUMBERS: ${{ inputs.version-numbers }} + run: | + cat << EOF > ${RUNNER_TEMP}/commit-msg.txt + IC: $(date +%Y-%m-%d) version update + + Automatically generated version number update + EOF + echo "${VERSION_NUMBERS}" | jq . | grep '^ ' >> ${RUNNER_TEMP}/commit-msg.txt + git status + if ! git diff --quiet; then + git commit -a -F ${RUNNER_TEMP}/commit-msg.txt + else + echo "No differences found, no commit needed" + fi + - name: Push IC branch run: | # Do not force-push direct to the base branch @@ -103,6 +167,18 @@ jobs: fi git push origin "${FORCE_FLAG}${IC_BRANCH}" + # Note that "gh pr create" will fail if a PR already exists + - name: Check for existing pull request + if: env.IC_BRANCH != env.BASE_BRANCH + run: | + gh pr list --base "${BASE_BRANCH}" --head "${IC_BRANCH}" --json number,title > ${RUNNER_TEMP}/pull-request.json + if [ "$(jq length ${RUNNER_TEMP}/pull-request.json)" -gt 0 ]; then + echo "Found existing PR:" + cat ${RUNNER_TEMP}/pull-request.json + else + rm ${RUNNER_TEMP}/pull-request.json + fi + - name: Create PR if: env.IC_BRANCH != env.BASE_BRANCH env: @@ -116,4 +192,8 @@ jobs: else LABEL_OPTS="-l ${PR_LABEL_IN}" fi - gh pr create -R "${GH_REPO}" -a "${GH_ACTOR}" -B "${BASE_BRANCH}" -H "${IC_BRANCH}" --title "${DATE_TAG} development snapshot" ${LABEL_OPTS} -F "${RUNNER_TEMP}/commit-msg.txt" + if [ -e ${RUNNER_TEMP}/pull-request.json ]; then + echo "Pull request already exists: ${{ github.server_url }}/${GH_REPO}/pull/$(jq '.[0].number' ${RUNNER_TEMP}/pull-request.json)" + else + gh pr create -R "${GH_REPO}" -a "${GH_ACTOR}" -B "${BASE_BRANCH}" -H "${IC_BRANCH}" --title "${DATE_TAG} development snapshot" ${LABEL_OPTS} -F "${RUNNER_TEMP}/commit-msg.txt" + fi