From c3fb775e82b1d15d5b21834457de68de53b1db6d Mon Sep 17 00:00:00 2001 From: Sharon Koech Date: Wed, 6 Aug 2025 11:30:33 +0300 Subject: [PATCH 01/13] Create tag-stable-commit.yml --- .github/workflows/tag-stable-commit.yml | 163 ++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 .github/workflows/tag-stable-commit.yml diff --git a/.github/workflows/tag-stable-commit.yml b/.github/workflows/tag-stable-commit.yml new file mode 100644 index 00000000..5c69b886 --- /dev/null +++ b/.github/workflows/tag-stable-commit.yml @@ -0,0 +1,163 @@ +# This workflow runs biweekly + +name: Tag stable MicroCeph commit + +# Controls when the action will run. Workflow runs when there is a new stable channel +# promoted on Snapcraft +on: +# Allows you to run this workflow manually from the Actions tab + workflow_dispatch: null +# schedule: +# - cron: '0 0 * * MON,THU' # Runs biweekly on Tuesdays and Thursdays +jobs: + tag-stable-commit: + # The type of runner that the job will run on + runs-on: ubuntu-latest + permissions: + contents: write # Needed for creating tags + steps: + - name: Checkout repository + uses: actions/checkout@v4 + # Install the MicroCeph snap + - name: Install MicroCeph snap + run: | + sudo snap install microceph + # Find the first name under "channels:" that includes "/stable:" + # and parse , and + - name: Extract channel information + id: snap + uses: actions/github-script@v7 + with: + script: | + const { execSync } = require('child_process'); + // Run `snap info microceph` + const info = execSync('snap info microceph', { encoding: 'utf-8' }); + const lines = info.split('\n'); + // Find the "channels:" header (ignoring indentation) + const headerIdx = lines.findIndex(l => l.trim().startsWith('channels:')); + if (headerIdx === -1) { + core.setFailed('Could not find "channels:" in snap info output'); + return; + } + // Get the first non-empty channel line after the header + const channelRaw = lines.slice(headerIdx + 1) + .find(l => l.includes('/stable:')); + if (!channelRaw) { + core.setFailed('Could not find a "/stable:" channel line'); + return; + } + core.info(`Channel line: "${channelRaw}"`); + // Parse version, and commit ID + const m = channelRaw.match( + /^\s*([a-z]+)\/stable:\s+([0-9.]+)\+snap([a-f0-9]+)\s/ + ); + if (!m) { + core.setFailed('Failed to parse channel line'); + return; + } + const [, codeName, version, commit] = m; + + const minCodeNameLength = 1; // At least 1 char + const minVersionLength = 6; // e.g. '19.2.0' or more + const minCommitLength= 7; // typical short git commit hash length + + // Add minimum length requirement to validate output variables + if (!codeName || codeName.length < minCodeNameLength) { + core.setFailed(`Invalid codeName: "${codeName}"`); + return; + } + if (!version || version.length < minVersionLength) { + core.setFailed(`Invalid version: "${version}"`); + return; + } + if (!commit || commit.length < minCommitLength) { + core.setFailed(`Invalid commit: "${commit}"`); + return; + } + + core.setOutput('codeName', codeName); + core.setOutput('version', version); + core.setOutput('commit', commit); + core.info(`codeName=${codeName}`); + core.info(`version=${version}`); + core.info(`commit=${commit}`); + + # Verify commit exists in the repo and print commit message first line + - name: Verify commit exists + uses: actions/github-script@v7 + with: + script: | + const target = '${{ steps.snap.outputs.commit }}'.slice(0, 7); // 7-char prefix + core.info(`Looking for a commit starting with "${target}" ...`); + const commits = await github.paginate( + github.rest.repos.listCommits, + { + owner: context.repo.owner, + repo: context.repo.repo, + per_page: 100 + } + ); + const hit = commits.find(c => c.sha.startsWith(target)); + if (hit) { + core.info(`Found commit: ${hit.sha} - ${hit.html_url}`); + // Print first line of the commit message + const firstLine = hit.commit.message.split('\n')[0]; + core.info(`Commit message first line: "${firstLine}"`); + } else { + core.setFailed(`No commit starting with "${target}" found in the repository`); + } + # Create or update tag pointing to the verified commit + # If the tag doesn't exist, create it + # If the tag exists, but it points to a different commit, update it (move it forward) + # If it already exists but points to the correct commit, do nothing + - name: Create or update stable tag for verified commit + uses: actions/github-script@v7 + with: + script: | + const commitSha = '${{ steps.snap.outputs.commit }}'; + const codeName = '${{ steps.snap.outputs.codeName }}'; + const version = '${{ steps.snap.outputs.version }}'; + const stableTag = `v${version}+${codeName}`; + core.info(`Proposed stable tag: ${stableTag}`); + + // Get existing tags + const tags = await github.paginate( + github.rest.repos.listTags, + { + owner: context.repo.owner, + repo: context.repo.repo, + per_page: 100 + } + ); + + const existingTag = tags.find(t => t.name === stableTag); + + if (existingTag) { + core.info(`Tag "${stableTag}" already exists.`); + if (existingTag.commit.sha === commitSha) { + core.info(`It already points to the correct commit (${commitSha}). Nothing to do.`); + return; + } else { + core.info(`Tag "${stableTag}" points to a different commit (${existingTag.commit.sha}). Updating to ${commitSha}...`); + await github.rest.git.updateRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `tags/${stableTag}`, + sha: commitSha, + force: true + }); + core.info(`Tag "${stableTag}" updated to point to ${commitSha}.`); + return; + } + } + + // Create tag if it doesn't exist + core.info(`Creating new tag "${stableTag}" pointing to commit ${commitSha}`); + await github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `refs/tags/${stableTag}`, + sha: commitSha + }); + core.info(`Tag "${stableTag}" created successfully.`); + From d51b72fefc9e58c00d89bf1c8d20123b8c37ba4c Mon Sep 17 00:00:00 2001 From: Sharon Koech Date: Wed, 6 Aug 2025 11:41:23 +0300 Subject: [PATCH 02/13] Update tag-stable-commit.yml --- .github/workflows/tag-stable-commit.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tag-stable-commit.yml b/.github/workflows/tag-stable-commit.yml index 5c69b886..caf6ae5c 100644 --- a/.github/workflows/tag-stable-commit.yml +++ b/.github/workflows/tag-stable-commit.yml @@ -5,10 +5,11 @@ name: Tag stable MicroCeph commit # Controls when the action will run. Workflow runs when there is a new stable channel # promoted on Snapcraft on: -# Allows you to run this workflow manually from the Actions tab - workflow_dispatch: null -# schedule: -# - cron: '0 0 * * MON,THU' # Runs biweekly on Tuesdays and Thursdays + # Trigger on PRs to main + pull_request: + types: [opened, synchronize, reopened] + branches: + - main # change if your default branch is different jobs: tag-stable-commit: # The type of runner that the job will run on From 184c09a8d41766bf3a6c34ad4fa4e80a046859d4 Mon Sep 17 00:00:00 2001 From: Sharon Koech Date: Wed, 6 Aug 2025 12:12:15 +0300 Subject: [PATCH 03/13] Update tag-stable-commit.yml --- .github/workflows/tag-stable-commit.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tag-stable-commit.yml b/.github/workflows/tag-stable-commit.yml index caf6ae5c..ae6f1c1a 100644 --- a/.github/workflows/tag-stable-commit.yml +++ b/.github/workflows/tag-stable-commit.yml @@ -29,6 +29,7 @@ jobs: id: snap uses: actions/github-script@v7 with: + github-token: ${{ env.GH_TOKEN }} script: | const { execSync } = require('child_process'); // Run `snap info microceph` From 1a1d41e40761e324f0f39e10d706cc2fa4084789 Mon Sep 17 00:00:00 2001 From: Sharon Koech Date: Thu, 7 Aug 2025 12:03:47 +0300 Subject: [PATCH 04/13] Update tag-stable-commit.yml --- .github/workflows/tag-stable-commit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tag-stable-commit.yml b/.github/workflows/tag-stable-commit.yml index ae6f1c1a..e0505771 100644 --- a/.github/workflows/tag-stable-commit.yml +++ b/.github/workflows/tag-stable-commit.yml @@ -29,7 +29,7 @@ jobs: id: snap uses: actions/github-script@v7 with: - github-token: ${{ env.GH_TOKEN }} + github-token: ${{ secrets.GITHUB_TOKEN }} script: | const { execSync } = require('child_process'); // Run `snap info microceph` From 5b776894ac1af49c367eab29ccadd3d7a5ecac52 Mon Sep 17 00:00:00 2001 From: Sharon Koech Date: Thu, 7 Aug 2025 12:18:17 +0300 Subject: [PATCH 05/13] Output full SHA --- .github/workflows/tag-stable-commit.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tag-stable-commit.yml b/.github/workflows/tag-stable-commit.yml index e0505771..7ebb1150 100644 --- a/.github/workflows/tag-stable-commit.yml +++ b/.github/workflows/tag-stable-commit.yml @@ -86,6 +86,7 @@ jobs: # Verify commit exists in the repo and print commit message first line - name: Verify commit exists + id: verify uses: actions/github-script@v7 with: script: | @@ -105,6 +106,7 @@ jobs: // Print first line of the commit message const firstLine = hit.commit.message.split('\n')[0]; core.info(`Commit message first line: "${firstLine}"`); + core.setOutput('full_sha', hit.sha); // Output full SHA } else { core.setFailed(`No commit starting with "${target}" found in the repository`); } @@ -116,7 +118,7 @@ jobs: uses: actions/github-script@v7 with: script: | - const commitSha = '${{ steps.snap.outputs.commit }}'; + const commitSha = '${{ steps.verify.outputs.full_sha }}'; const codeName = '${{ steps.snap.outputs.codeName }}'; const version = '${{ steps.snap.outputs.version }}'; const stableTag = `v${version}+${codeName}`; From ce20573ea8f9eadeb5f843a17a81dd3e7cfc9a30 Mon Sep 17 00:00:00 2001 From: Sharon Koech Date: Thu, 7 Aug 2025 12:44:06 +0300 Subject: [PATCH 06/13] Add personal access token --- .github/workflows/tag-stable-commit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tag-stable-commit.yml b/.github/workflows/tag-stable-commit.yml index 7ebb1150..ece1d934 100644 --- a/.github/workflows/tag-stable-commit.yml +++ b/.github/workflows/tag-stable-commit.yml @@ -29,7 +29,7 @@ jobs: id: snap uses: actions/github-script@v7 with: - github-token: ${{ secrets.GITHUB_TOKEN }} + github-token: ${{ secrets.PAT_TOKEN }} script: | const { execSync } = require('child_process'); // Run `snap info microceph` From 553a122f4dd75772297d0fb747861f557aed27d5 Mon Sep 17 00:00:00 2001 From: Sharon Koech Date: Thu, 7 Aug 2025 12:50:51 +0300 Subject: [PATCH 07/13] Add GH token to other steps --- .github/workflows/tag-stable-commit.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/tag-stable-commit.yml b/.github/workflows/tag-stable-commit.yml index ece1d934..d538f6b8 100644 --- a/.github/workflows/tag-stable-commit.yml +++ b/.github/workflows/tag-stable-commit.yml @@ -89,6 +89,7 @@ jobs: id: verify uses: actions/github-script@v7 with: + github-token: ${{ secrets.PAT_TOKEN }} script: | const target = '${{ steps.snap.outputs.commit }}'.slice(0, 7); // 7-char prefix core.info(`Looking for a commit starting with "${target}" ...`); @@ -117,6 +118,7 @@ jobs: - name: Create or update stable tag for verified commit uses: actions/github-script@v7 with: + github-token: ${{ secrets.PAT_TOKEN }} script: | const commitSha = '${{ steps.verify.outputs.full_sha }}'; const codeName = '${{ steps.snap.outputs.codeName }}'; From bb098359edb8c840ba8453a9011c2944de55fb36 Mon Sep 17 00:00:00 2001 From: Sharon Koech Date: Thu, 7 Aug 2025 16:03:31 +0300 Subject: [PATCH 08/13] Fix indentation --- .github/workflows/tag-stable-commit.yml | 44 ++++++++++++------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/.github/workflows/tag-stable-commit.yml b/.github/workflows/tag-stable-commit.yml index d538f6b8..07a1d6a2 100644 --- a/.github/workflows/tag-stable-commit.yml +++ b/.github/workflows/tag-stable-commit.yml @@ -89,28 +89,28 @@ jobs: id: verify uses: actions/github-script@v7 with: - github-token: ${{ secrets.PAT_TOKEN }} - script: | - const target = '${{ steps.snap.outputs.commit }}'.slice(0, 7); // 7-char prefix - core.info(`Looking for a commit starting with "${target}" ...`); - const commits = await github.paginate( - github.rest.repos.listCommits, - { - owner: context.repo.owner, - repo: context.repo.repo, - per_page: 100 - } - ); - const hit = commits.find(c => c.sha.startsWith(target)); - if (hit) { - core.info(`Found commit: ${hit.sha} - ${hit.html_url}`); - // Print first line of the commit message - const firstLine = hit.commit.message.split('\n')[0]; - core.info(`Commit message first line: "${firstLine}"`); - core.setOutput('full_sha', hit.sha); // Output full SHA - } else { - core.setFailed(`No commit starting with "${target}" found in the repository`); - } + github-token: ${{ secrets.PAT_TOKEN }} + script: | + const target = '${{ steps.snap.outputs.commit }}'.slice(0, 7); // 7-char prefix + core.info(`Looking for a commit starting with "${target}" ...`); + const commits = await github.paginate( + github.rest.repos.listCommits, + { + owner: context.repo.owner, + repo: context.repo.repo, + per_page: 100 + } + ); + const hit = commits.find(c => c.sha.startsWith(target)); + if (hit) { + core.info(`Found commit: ${hit.sha} - ${hit.html_url}`); + // Print first line of the commit message + const firstLine = hit.commit.message.split('\n')[0]; + core.info(`Commit message first line: "${firstLine}"`); + core.setOutput('full_sha', hit.sha); // Output full SHA + } else { + core.setFailed(`No commit starting with "${target}" found in the repository`); + } # Create or update tag pointing to the verified commit # If the tag doesn't exist, create it # If the tag exists, but it points to a different commit, update it (move it forward) From 32296cac512801e5cefe8f2222661a1ee1ad1656 Mon Sep 17 00:00:00 2001 From: Sharon Koech Date: Thu, 7 Aug 2025 16:12:56 +0300 Subject: [PATCH 09/13] Test with GITHUB_TOKEN --- .github/workflows/tag-stable-commit.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tag-stable-commit.yml b/.github/workflows/tag-stable-commit.yml index 07a1d6a2..de80cf90 100644 --- a/.github/workflows/tag-stable-commit.yml +++ b/.github/workflows/tag-stable-commit.yml @@ -29,7 +29,7 @@ jobs: id: snap uses: actions/github-script@v7 with: - github-token: ${{ secrets.PAT_TOKEN }} + github-token: ${{ secrets.GITHUB_TOKEN }} script: | const { execSync } = require('child_process'); // Run `snap info microceph` @@ -89,7 +89,7 @@ jobs: id: verify uses: actions/github-script@v7 with: - github-token: ${{ secrets.PAT_TOKEN }} + github-token: ${{ secrets.GITHUB_TOKEN }} script: | const target = '${{ steps.snap.outputs.commit }}'.slice(0, 7); // 7-char prefix core.info(`Looking for a commit starting with "${target}" ...`); @@ -118,7 +118,7 @@ jobs: - name: Create or update stable tag for verified commit uses: actions/github-script@v7 with: - github-token: ${{ secrets.PAT_TOKEN }} + github-token: ${{ secrets.GITHUB_TOKEN }} script: | const commitSha = '${{ steps.verify.outputs.full_sha }}'; const codeName = '${{ steps.snap.outputs.codeName }}'; From 3fbf708f0fe841868e9c07bca40890da2c806875 Mon Sep 17 00:00:00 2001 From: Sharon Koech Date: Thu, 7 Aug 2025 16:27:49 +0300 Subject: [PATCH 10/13] Add fine-grained token --- .github/workflows/tag-stable-commit.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tag-stable-commit.yml b/.github/workflows/tag-stable-commit.yml index de80cf90..11d2251d 100644 --- a/.github/workflows/tag-stable-commit.yml +++ b/.github/workflows/tag-stable-commit.yml @@ -29,7 +29,7 @@ jobs: id: snap uses: actions/github-script@v7 with: - github-token: ${{ secrets.GITHUB_TOKEN }} + github-token: ${{ secrets.MY_PAT }} script: | const { execSync } = require('child_process'); // Run `snap info microceph` @@ -89,7 +89,7 @@ jobs: id: verify uses: actions/github-script@v7 with: - github-token: ${{ secrets.GITHUB_TOKEN }} + github-token: ${{ secrets.MY_PAT }} script: | const target = '${{ steps.snap.outputs.commit }}'.slice(0, 7); // 7-char prefix core.info(`Looking for a commit starting with "${target}" ...`); @@ -118,7 +118,7 @@ jobs: - name: Create or update stable tag for verified commit uses: actions/github-script@v7 with: - github-token: ${{ secrets.GITHUB_TOKEN }} + github-token: ${{ secrets.MY_PAT }} script: | const commitSha = '${{ steps.verify.outputs.full_sha }}'; const codeName = '${{ steps.snap.outputs.codeName }}'; From be51e3fa5dd29ceb6d4a800f384a5b88b326f1ca Mon Sep 17 00:00:00 2001 From: Sharon Koech Date: Thu, 7 Aug 2025 16:54:32 +0300 Subject: [PATCH 11/13] Regenerate and add token --- .github/workflows/tag-stable-commit.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tag-stable-commit.yml b/.github/workflows/tag-stable-commit.yml index 11d2251d..07a1d6a2 100644 --- a/.github/workflows/tag-stable-commit.yml +++ b/.github/workflows/tag-stable-commit.yml @@ -29,7 +29,7 @@ jobs: id: snap uses: actions/github-script@v7 with: - github-token: ${{ secrets.MY_PAT }} + github-token: ${{ secrets.PAT_TOKEN }} script: | const { execSync } = require('child_process'); // Run `snap info microceph` @@ -89,7 +89,7 @@ jobs: id: verify uses: actions/github-script@v7 with: - github-token: ${{ secrets.MY_PAT }} + github-token: ${{ secrets.PAT_TOKEN }} script: | const target = '${{ steps.snap.outputs.commit }}'.slice(0, 7); // 7-char prefix core.info(`Looking for a commit starting with "${target}" ...`); @@ -118,7 +118,7 @@ jobs: - name: Create or update stable tag for verified commit uses: actions/github-script@v7 with: - github-token: ${{ secrets.MY_PAT }} + github-token: ${{ secrets.PAT_TOKEN }} script: | const commitSha = '${{ steps.verify.outputs.full_sha }}'; const codeName = '${{ steps.snap.outputs.codeName }}'; From 66dd7ce77747c2fb5c8443aaf9098fba8c2a5404 Mon Sep 17 00:00:00 2001 From: Sharon Koech Date: Thu, 7 Aug 2025 17:01:59 +0300 Subject: [PATCH 12/13] Target my fork Signed-off-by: Sharon Koech --- .github/workflows/tag-stable-commit.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/tag-stable-commit.yml b/.github/workflows/tag-stable-commit.yml index 07a1d6a2..2d9839cf 100644 --- a/.github/workflows/tag-stable-commit.yml +++ b/.github/workflows/tag-stable-commit.yml @@ -96,8 +96,8 @@ jobs: const commits = await github.paginate( github.rest.repos.listCommits, { - owner: context.repo.owner, - repo: context.repo.repo, + owner: skoech, + repo: skoech/microceph, per_page: 100 } ); @@ -130,8 +130,8 @@ jobs: const tags = await github.paginate( github.rest.repos.listTags, { - owner: context.repo.owner, - repo: context.repo.repo, + owner: skoech, + repo: skoech/microceph, per_page: 100 } ); @@ -146,8 +146,8 @@ jobs: } else { core.info(`Tag "${stableTag}" points to a different commit (${existingTag.commit.sha}). Updating to ${commitSha}...`); await github.rest.git.updateRef({ - owner: context.repo.owner, - repo: context.repo.repo, + owner: skoech, + repo: skoech/microceph, ref: `tags/${stableTag}`, sha: commitSha, force: true @@ -160,8 +160,8 @@ jobs: // Create tag if it doesn't exist core.info(`Creating new tag "${stableTag}" pointing to commit ${commitSha}`); await github.rest.git.createRef({ - owner: context.repo.owner, - repo: context.repo.repo, + owner: skoech, + repo: skoech/microceph, ref: `refs/tags/${stableTag}`, sha: commitSha }); From f7bc71c6e173bb27de496481c742cbe3a0430dfe Mon Sep 17 00:00:00 2001 From: Sharon Koech Date: Thu, 7 Aug 2025 17:06:17 +0300 Subject: [PATCH 13/13] Fix syntax Signed-off-by: Sharon Koech --- .github/workflows/tag-stable-commit.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/tag-stable-commit.yml b/.github/workflows/tag-stable-commit.yml index 2d9839cf..1a155a84 100644 --- a/.github/workflows/tag-stable-commit.yml +++ b/.github/workflows/tag-stable-commit.yml @@ -96,8 +96,8 @@ jobs: const commits = await github.paginate( github.rest.repos.listCommits, { - owner: skoech, - repo: skoech/microceph, + owner: 'skoech', + repo: 'skoech/microceph', per_page: 100 } ); @@ -130,8 +130,8 @@ jobs: const tags = await github.paginate( github.rest.repos.listTags, { - owner: skoech, - repo: skoech/microceph, + owner: 'skoech', + repo: 'skoech/microceph', per_page: 100 } ); @@ -146,8 +146,8 @@ jobs: } else { core.info(`Tag "${stableTag}" points to a different commit (${existingTag.commit.sha}). Updating to ${commitSha}...`); await github.rest.git.updateRef({ - owner: skoech, - repo: skoech/microceph, + owner: 'skoech', + repo: 'skoech/microceph', ref: `tags/${stableTag}`, sha: commitSha, force: true @@ -160,8 +160,8 @@ jobs: // Create tag if it doesn't exist core.info(`Creating new tag "${stableTag}" pointing to commit ${commitSha}`); await github.rest.git.createRef({ - owner: skoech, - repo: skoech/microceph, + owner: 'skoech', + repo: 'skoech/microceph', ref: `refs/tags/${stableTag}`, sha: commitSha });