From 24730167da7aa638430a7e57e8d6b39d895d33f8 Mon Sep 17 00:00:00 2001 From: Satyam Singh <68936323+Thedarkmatter10@users.noreply.github.com> Date: Sat, 14 Jun 2025 02:17:24 +0530 Subject: [PATCH] =?UTF-8?q?fix(common.yml):=20globalize=20CURRENT=5FSDK,?= =?UTF-8?q?=20improve=20shell=20safety=20and=20=20imp=E2=80=A6=20(#178)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 🔧 Improvements Summary This PR introduces three improvements focused on safety, maintainability, and readability of the GitHub Actions workflow. --- ### 1. Define Global Environment Variable **Before:** Environment variable `CURRENT_SDK` was defined repeatedly in multiple steps. **After:** Declared in gloabally one time. #### Why This Matters: - Eliminates duplication across steps. - Makes it easier to update or remove the variable in the future. - Still allows per-step override when necessary. ### 2. Fix Unsafe Shell Conditional on inputs.release - Using **[[ ... ]]** **instea**d of **[ ... ]** for conditionals. - Adding **double quotes** around inputs and refs to **avoid** evaluation issues. **PREVIOUSLY FIXED** Containerization project. [https://github.com/apple/containerization/pull/68](url) ### 3. Removed EXCLUSION AND TODO comment. #### Affected Steps: `check Formatting` `make proto` ### Improvements: Now that the repositories are public, we no longer need to exclude files like Package.swift and Package.resolved from formatting and proto checks. - Removed EXCLUDES logic - Removed related TODO comments - Updated git diff checks to include all files @wlan0 @katiewasnothere --- .github/workflows/common.yml | 38 ++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/.github/workflows/common.yml b/.github/workflows/common.yml index 67dbf834..7383f21e 100644 --- a/.github/workflows/common.yml +++ b/.github/workflows/common.yml @@ -16,64 +16,79 @@ jobs: permissions: contents: read packages: read + env: + CURRENT_SDK: y steps: - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 + - name: Update containerization run: | /usr/bin/swift package update containerization + - name: Check formatting run: | ./scripts/install-hawkeye.sh make fmt - if ! git diff --quiet -- . ':(exclude)Package.swift' ':(exclude)Package.resolved'; then echo "The following files require formatting or license header updates:\n$(git diff --name-only)" ; false ; fi + + if ! git diff --quiet -- . ; then + echo "❌ The following files require formatting or license header updates:" + git diff --name-only -- . + false + fi + - name: Check protobuf run: | make protos - - # TODO [launch]: TEMPORARILY we need to exclude these files since we had to modify them to add - # the github token for pulling the private repos. - if ! git diff --quiet -- . ':(exclude)Package.swift' ':(exclude)Package.resolved' ':(exclude)Protobuf.Makefile'; then echo "The following files require formatting or license header updates:\n$(git diff --name-only)" ; false ; fi - env: - CURRENT_SDK: y + if ! git diff --quiet -- . ; then + echo "❌ The following files require formatting or license header updates:" + git diff --name-only -- . + false + fi + - name: Set build configuration run: | echo "BUILD_CONFIGURATION=debug" >> $GITHUB_ENV - if [ ${{ inputs.release }} == true ]; then + if [[ "${{ inputs.release }}" == "true" ]]; then echo "BUILD_CONFIGURATION=release" >> $GITHUB_ENV fi + - name: Make the container project and docs run: | make container dsym docs tar cfz _site.tgz _site env: DEVELOPER_DIR: "/Applications/Xcode_16.3.app/Contents/Developer" - CURRENT_SDK: y + - name: Create package run: | mkdir -p outputs mv bin/${{ env.BUILD_CONFIGURATION }}/container-installer-unsigned.pkg outputs mv bin/${{ env.BUILD_CONFIGURATION }}/bundle/container-dSYM.zip outputs + - name: Test the container project run: | launchctl setenv HTTP_PROXY $HTTP_PROXY make test cleancontent install-kernel integration env: DEVELOPER_DIR: "/Applications/Xcode_16.3.app/Contents/Developer" - CURRENT_SDK: y + CURRENT_SDK: y # explicitly repeated due to local env block + - name: Save documentation artifact uses: actions/upload-artifact@v4 with: name: api-docs path: "./_site.tgz" retention-days: 14 + - name: Save package artifacts uses: actions/upload-artifact@v4 with: name: container-package path: ${{ github.workspace }}/outputs + uploadPages: # Separate upload step required because upload-pages-artifact needs # gtar which is not on the macOS runner. @@ -84,13 +99,16 @@ jobs: steps: - name: Setup Pages uses: actions/configure-pages@v5 + - name: Download a single artifact uses: actions/download-artifact@v4 with: name: api-docs + - name: Add API docs to documentation run: | tar xfz _site.tgz + - name: Upload Artifact uses: actions/upload-pages-artifact@v3 with: