From 606c973a71a39e9cb032abe4766e070f2718e520 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 9 Jun 2025 19:00:50 +0000 Subject: [PATCH] Implement dynamic versioning in CI workflow This commit introduces a dynamic versioning strategy for package builds in the GitHub Actions CI workflow. Changes include: - Added a `.ver` file to store the base version number (e.g., "1.0.1"). - Modified `.github/workflows/R-CMD-check.yml`: - Reads the base version from the `.ver` file. - Retrieves the short Git commit SHA. - Constructs a dynamic version string in the format "BASE_VERSION.COMMIT_SHA" (e.g., "1.0.1.abcdef0"). - Temporarily updates the `Version:` field in the `DESCRIPTION` file with this dynamic version before building the package. - Names the uploaded package tarball artifact using this dynamic version string (e.g., `processcontrol-1.0.1.abcdef0.tar.gz`). This approach ensures that each build artifact is uniquely identifiable by its base version and the specific commit it was built from. --- .github/workflows/R-CMD-check.yml | 73 +++++++++++++++++++++++++++++++ .ver | 1 + 2 files changed, 74 insertions(+) create mode 100644 .github/workflows/R-CMD-check.yml create mode 100644 .ver diff --git a/.github/workflows/R-CMD-check.yml b/.github/workflows/R-CMD-check.yml new file mode 100644 index 0000000..ce36868 --- /dev/null +++ b/.github/workflows/R-CMD-check.yml @@ -0,0 +1,73 @@ +name: R CMD Check & Build + +on: + push: + branches: [ main, master ] + pull_request: + branches: [ main, master ] + +jobs: + R-CMD-check: + runs-on: ubuntu-latest + permissions: + contents: read # Needed to read .ver and commit SHA + # contents: write # Only if we were to commit the DESCRIPTION file change back + + steps: + - name: Check out repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Required to get commit SHA + + - name: Set up R + uses: r-lib/actions/setup-R@v2 + with: + r-version: '4.5.0' + + - name: Read version from .ver file + id: get_version + run: echo "VERSION=$(cat .ver)" >> $GITHUB_OUTPUT + + - name: Get short commit SHA + id: get_sha + run: echo "SHA=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + + - name: Construct dynamic version string + id: dynamic_version + run: echo "FULL_VERSION=${{ steps.get_version.outputs.VERSION }}.${{ steps.get_sha.outputs.SHA }}" >> $GITHUB_OUTPUT + + - name: Update DESCRIPTION file with dynamic version + run: | + echo "Using version for DESCRIPTION: ${{ steps.dynamic_version.outputs.FULL_VERSION }}" + sed -i "s/^Version: .*/Version: ${{ steps.dynamic_version.outputs.FULL_VERSION }}/" DESCRIPTION + echo "DESCRIPTION file after update:" + cat DESCRIPTION + + - name: Install dependencies + uses: r-lib/actions/setup-R-dependencies@v2 + with: + packages: | + any::packrat + any::rcpp + any::plyr + needs: check + + - name: Check package + uses: r-lib/actions/check-R-package@v2 + with: + upload-snapshots: true # Useful for debugging check failures + + - name: Build package + id: build + run: | + R CMD build . + # Find the built package name + PKG_FILE=$(ls *.tar.gz) + echo "PKG_FILE=$PKG_FILE" >> $GITHUB_OUTPUT + echo "Built package file: $PKG_FILE" + + - name: Upload package tarball + uses: actions/upload-artifact@v4 + with: + name: processcontrol-${{ steps.dynamic_version.outputs.FULL_VERSION }} + path: ${{ steps.build.outputs.PKG_FILE }} diff --git a/.ver b/.ver new file mode 100644 index 0000000..7dea76e --- /dev/null +++ b/.ver @@ -0,0 +1 @@ +1.0.1