mirror of
https://github.com/apple/container.git
synced 2026-07-21 00:41:32 +00:00
See https://github.com/swiftlang/github-workflows/issues/167 for additional context This approach aligns with security best practices, as detailed in the following documentation: - https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions - https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#defining-access-for-the-github_token-scopes - https://openssf.org/blog/2024/08/12/mitigating-attack-vectors-in-github-workflows/ The default GITHUB_TOKEN permissions are defined at the repository level. This PR modifies the workflow-level overrides to conform to OpenSSF best practices -> defense in depth. Allow me to quote OpenSSF: https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions > The highest score is awarded when the permissions definitions in each workflow's yaml file are set as read-only at the top level and the required write permissions are declared at the run-level.” > Remediation steps > - Set top-level permissions as read-all or contents: read as described in GitHub's documentation. > - Set any required write permissions at the job-level. Only set the permissions required for that job; do not set permissions: write-all at the job level. Compare to the LLVM project: Top-level: contents read, e.g. https://github.com/swiftlang/llvm-project/blob/next/.github/workflows/build-ci-container-windows.yml#L3-L4 -> this makes it future-proof Job-level: Allow write permissions as needed, e.g. https://github.com/swiftlang/llvm-project/blob/next/.github/workflows/build-ci-container-windows.yml#L53-L58 Signed-off-by: Melissa Kilby <mkilby@apple.com>
117 lines
3.3 KiB
YAML
117 lines
3.3 KiB
YAML
name: container project - common jobs
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
release:
|
|
type: boolean
|
|
description: "Publish this build for release"
|
|
default: false
|
|
|
|
jobs:
|
|
buildAndTest:
|
|
name: Build and test the project
|
|
if: github.repository == 'apple/container'
|
|
timeout-minutes: 60
|
|
runs-on: [self-hosted, macos, sequoia, ARM64]
|
|
permissions:
|
|
contents: read
|
|
packages: read
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Check formatting
|
|
run: |
|
|
./scripts/install-hawkeye.sh
|
|
make fmt
|
|
|
|
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
|
|
if ! git diff --quiet -- . ; then
|
|
echo "❌ The following files require formatting or license header updates:"
|
|
git diff --name-only -- .
|
|
false
|
|
fi
|
|
env:
|
|
DEVELOPER_DIR: "/Applications/Xcode-latest.app/Contents/Developer"
|
|
|
|
- name: Set build configuration
|
|
run: |
|
|
echo "BUILD_CONFIGURATION=debug" >> $GITHUB_ENV
|
|
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-latest.app/Contents/Developer"
|
|
|
|
- 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: |
|
|
APP_ROOT=$(mktemp -d -p "${RUNNER_TEMP}")
|
|
trap 'rm -rf "${APP_ROOT}"; echo Removing data directory ${APP_ROOT}' EXIT
|
|
echo "Created data directory ${APP_ROOT}"
|
|
make APP_ROOT="${APP_ROOT}" test install-kernel integration
|
|
env:
|
|
DEVELOPER_DIR: "/Applications/Xcode-latest.app/Contents/Developer"
|
|
|
|
- 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.
|
|
name: Upload artifact for GitHub Pages
|
|
needs: buildAndTest
|
|
timeout-minutes: 5
|
|
runs-on: ubuntu-latest
|
|
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:
|
|
path: "./_site"
|