diff --git a/.github/workflows/containers-build-template.yml b/.github/workflows/containers-build-template.yml deleted file mode 100644 index b356f11..0000000 --- a/.github/workflows/containers-build-template.yml +++ /dev/null @@ -1,98 +0,0 @@ -name: Build Containers Template - -permissions: - contents: read - -on: - workflow_call: - inputs: - release: - type: boolean - description: "Build using the Release configuration" - default: false - -env: - DEVELOPER_DIR: "/Applications/Xcode_26.6.app/Contents/Developer" - -jobs: - build: - name: Build - if: github.repository == 'try-containers/Containers' - timeout-minutes: 60 - runs-on: macos-26 - env: - BUILD_CONFIGURATION: ${{ inputs.release && 'Release' || 'Debug' }} - - steps: - - name: Checkout repository - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 - with: - fetch-depth: 0 - - - name: Show Xcode version - run: xcodebuild -version - - - name: Check formatting - run: | - swift format --recursive --configuration .swift-format -i $(find . -type f -name '*.swift' -not -path "*/.*") - git diff - if ! git diff --quiet ; then echo the following files require formatting: ; git diff --name-only ; false ; fi - - - name: Lint - run: | - swift format lint --strict --recursive --configuration .swift-format $(find . -type f -name '*.swift' -not -path "*/.*") - - - name: Resolve packages - run: | - xcodebuild -resolvePackageDependencies \ - -project Containers.xcodeproj \ - -scheme "Containers (macOS)" - - - name: Build - run: | - set -o pipefail - xcodebuild build \ - -project Containers.xcodeproj \ - -scheme "Containers (macOS)" \ - -configuration "${BUILD_CONFIGURATION}" \ - -destination 'platform=macOS' \ - CODE_SIGNING_ALLOWED=NO - - test: - name: Test - if: github.repository == 'try-containers/Containers' - timeout-minutes: 60 - runs-on: macos-26 - - steps: - - name: Checkout repository - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 - with: - fetch-depth: 0 - - - name: Show Xcode version - run: xcodebuild -version - - - name: Resolve packages - run: | - xcodebuild -resolvePackageDependencies \ - -project Containers.xcodeproj \ - -scheme ContainersCoreTests - - - name: Test - run: | - set -o pipefail - xcodebuild test \ - -project Containers.xcodeproj \ - -scheme ContainersCoreTests \ - -destination 'platform=macOS' \ - -resultBundlePath TestResults.xcresult \ - CODE_SIGNING_ALLOWED=NO - - - name: Save test results artifact - if: failure() - uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6 - with: - name: test-results - path: TestResults.xcresult - retention-days: 14 diff --git a/.github/workflows/containers-build.yml b/.github/workflows/containers-build.yml index 0029b7a..be70fc8 100644 --- a/.github/workflows/containers-build.yml +++ b/.github/workflows/containers-build.yml @@ -11,7 +11,106 @@ on: - main - release/* +env: + DEVELOPER_DIR: "/Applications/Xcode_26.6.app/Contents/Developer" + jobs: - containers: - uses: ./.github/workflows/containers-build-template.yml - secrets: inherit + build: + name: Build + if: github.repository == 'try-containers/Containers' + timeout-minutes: 60 + runs-on: macos-26 + + steps: + - name: Checkout repository + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 + with: + fetch-depth: 0 + + - name: Show Xcode version + run: xcodebuild -version + + - name: Check formatting + run: | + swift format --recursive --configuration .swift-format -i $(find . -type f -name '*.swift' -not -path "*/.*") + git diff + if ! git diff --quiet ; then echo the following files require formatting: ; git diff --name-only ; false ; fi + + - name: Lint + run: | + swift format lint --strict --recursive --configuration .swift-format $(find . -type f -name '*.swift' -not -path "*/.*") + + - name: Resolve packages + run: | + xcodebuild -resolvePackageDependencies \ + -project Containers.xcodeproj \ + -scheme "Containers (macOS)" + + # Builds the app and every test target in the scheme's test action, and + # writes the .xctestrun file that lists them for the Test job. + - name: Build + run: | + set -o pipefail + xcodebuild build-for-testing \ + -project Containers.xcodeproj \ + -scheme "Containers (macOS)" \ + -configuration Debug \ + -destination 'platform=macOS' \ + -derivedDataPath DerivedData \ + CODE_SIGNING_ALLOWED=NO + + # The archive keeps the executable permissions and symbolic links that an + # artifact loses. Intermediate files the tests don't run are left out. + - name: Archive build products + run: | + tar -C DerivedData/Build/Products \ + --exclude '*.o' \ + --exclude '*.swiftmodule' \ + --exclude '*.dSYM' \ + --exclude '*.modulemap' \ + --exclude 'include' \ + -czf BuildProducts.tar.gz . + + - name: Save build products artifact + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: build-products + path: BuildProducts.tar.gz + retention-days: 1 + + test: + name: Test + needs: build + timeout-minutes: 60 + runs-on: macos-26 + + steps: + - name: Show Xcode version + run: xcodebuild -version + + - name: Download build products artifact + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: build-products + + - name: Extract build products + run: | + mkdir BuildProducts + tar -C BuildProducts -xzf BuildProducts.tar.gz + + # Runs the Build job's products, with every test target in its .xctestrun file. + - name: Test + run: | + set -o pipefail + xcodebuild test-without-building \ + -xctestrun BuildProducts/*.xctestrun \ + -destination 'platform=macOS' \ + -resultBundlePath TestResults.xcresult + + - name: Save test results artifact + if: failure() + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: test-results + path: TestResults.xcresult + retention-days: 14 diff --git a/.github/workflows/containers-release.yml b/.github/workflows/containers-release.yml index 33385b7..0fb9407 100644 --- a/.github/workflows/containers-release.yml +++ b/.github/workflows/containers-release.yml @@ -4,8 +4,8 @@ permissions: contents: write # App Store Connect can't notify GitHub directly, so this runs by hand once a -# version is live, and publishes a release from the public App Store lookup. A -# relay for App Store Connect webhooks can send the app-store-release dispatch. +# version is live. It publishes the version's draft release with a Mac App Store +# link. A relay for App Store Connect webhooks can send the app-store-release dispatch. on: workflow_dispatch: repository_dispatch: @@ -43,43 +43,39 @@ jobs: echo "version=${VERSION}" >> "${GITHUB_OUTPUT}" echo "url=${STORE_URL}" >> "${GITHUB_OUTPUT}" - - name: Check for a release + # Pushing a version tag creates the version's draft release, whose notes + # are written by hand. + - name: Check for a draft release id: check env: VERSION: ${{ steps.store.outputs.version }} run: | - if gh release view "${VERSION}" > /dev/null 2>&1 ; then - echo "Release ${VERSION} already exists." + if ! RELEASE=$(gh release view "${VERSION}" --json isDraft,body 2> /dev/null) ; then + echo "::warning::Version ${VERSION} is live, but there's no release for it. Pushing tag ${VERSION} creates its draft." echo "publish=false" >> "${GITHUB_OUTPUT}" - elif ! gh api "repos/${GH_REPO}/git/ref/tags/${VERSION}" > /dev/null 2>&1 ; then - echo "::warning::Version ${VERSION} is live, but there's no tag ${VERSION} to release." + elif [ "$(jq -r '.isDraft' <<< "${RELEASE}")" != "true" ] ; then + echo "Release ${VERSION} is already published." + echo "publish=false" >> "${GITHUB_OUTPUT}" + elif [ -z "$(jq -r '.body // empty' <<< "${RELEASE}")" ] ; then + echo "::warning::The draft release for ${VERSION} has no notes yet." echo "publish=false" >> "${GITHUB_OUTPUT}" else echo "publish=true" >> "${GITHUB_OUTPUT}" fi - # The notes are the version's What's New text from App Store Connect. - # A first version can't have any; its release is written by hand. - name: Publish release if: steps.check.outputs.publish == 'true' env: VERSION: ${{ steps.store.outputs.version }} STORE_URL: ${{ steps.store.outputs.url }} run: | - NOTES=$(jq -r '.results[0].releaseNotes // empty' "${RUNNER_TEMP}/lookup.json") - - if [ -z "${NOTES}" ] ; then - echo "::warning::Version ${VERSION} has no What's New text, so its release needs writing by hand." - exit 0 - fi - { - printf '%s\n\n' "${NOTES}" - echo "[Download Containers ${VERSION} on the Mac App Store](${STORE_URL})" + gh release view "${VERSION}" --json body --jq '.body' + echo + echo "[Download Containers on the Mac App Store](${STORE_URL})" } > "${RUNNER_TEMP}/notes.md" - gh release create "${VERSION}" \ - --verify-tag \ + gh release edit "${VERSION}" \ + --draft=false \ --latest \ - --title "Containers ${VERSION}" \ --notes-file "${RUNNER_TEMP}/notes.md" diff --git a/.github/workflows/containers-testflight.yml b/.github/workflows/containers-testflight.yml index ce2ed34..f105706 100644 --- a/.github/workflows/containers-testflight.yml +++ b/.github/workflows/containers-testflight.yml @@ -3,13 +3,16 @@ name: Deploy to TestFlight permissions: contents: read -# Version tags, such as 0.2 or 0.2.1. A tag push can't be filtered by branch, -# so the validate job checks that the tag is on main. +# Version tags, such as 0.2 or 0.2.1, upload the version's final build and +# create its draft release. A tag push can't be filtered by branch, so the +# validate job checks that the tag is on main. Running the workflow by hand +# uploads a test build of the chosen branch, with no tag or release. on: push: tags: - '[0-9]+.[0-9]+' - '[0-9]+.[0-9]+.[0-9]+' + workflow_dispatch: concurrency: group: testflight @@ -19,8 +22,13 @@ jobs: name: Validate tag if: github.repository == 'try-containers/Containers' runs-on: ubuntu-latest + permissions: + actions: read + contents: read env: VERSION: ${{ github.ref_name }} + GH_REPO: ${{ github.repository }} + GH_TOKEN: ${{ github.token }} steps: - name: Checkout repository @@ -29,22 +37,32 @@ jobs: fetch-depth: 0 - name: Check that the tag is on main + if: github.ref_type == 'tag' run: | if ! git merge-base --is-ancestor "${GITHUB_SHA}" origin/main ; then echo "::error::Tag ${VERSION} points to a commit that isn't on main." false fi - containers: - needs: validate - uses: ./.github/workflows/containers-build-template.yml - secrets: inherit - with: - release: true + # Build & Test runs on the commit when it's pushed to main. Re-run this + # workflow once that run passes. + - name: Check that Build & Test passed + if: github.ref_type == 'tag' + run: | + CONCLUSION=$( + gh api "repos/${GH_REPO}/actions/workflows/containers-build.yml/runs?head_sha=${GITHUB_SHA}&status=completed" \ + --jq '.workflow_runs[0].conclusion // empty' + ) + + if [ "${CONCLUSION}" != "success" ] ; then + echo "::error::Build & Test hasn't passed on ${GITHUB_SHA}, the commit for tag ${VERSION}." + false + fi + # Formatting, lint and tests run on every pull request; the archive builds the app. deploy: name: Upload to TestFlight - needs: containers + needs: validate timeout-minutes: 60 runs-on: macos-26 env: @@ -96,6 +114,7 @@ jobs: -scheme "Containers (macOS)" - name: Check the version + if: github.ref_type == 'tag' run: | PROJECT_VERSION=$( xcodebuild -showBuildSettings -json \ @@ -173,3 +192,31 @@ jobs: run: | security delete-keychain "${KEYCHAIN_PATH}" || true rm -f "${API_KEY_PATH}" + + # The notes are written by hand in the draft, with the pull requests for each + # change. Publish Release publishes it once the version is live. + draft: + name: Create draft release + needs: deploy + if: github.ref_type == 'tag' + runs-on: ubuntu-latest + permissions: + contents: write + env: + VERSION: ${{ github.ref_name }} + GH_REPO: ${{ github.repository }} + GH_TOKEN: ${{ github.token }} + + steps: + - name: Create draft release + run: | + if gh release view "${VERSION}" > /dev/null 2>&1 ; then + echo "Release ${VERSION} already exists." + exit 0 + fi + + gh release create "${VERSION}" \ + --draft \ + --verify-tag \ + --title "Containers ${VERSION}" \ + --notes "" diff --git a/AGENTS.md b/AGENTS.md index 9b8c5d6..3cad203 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -6,8 +6,8 @@ Guidance for coding agents working in this repository. The project is a single Xcode project with two schemes: -- `Containers (macOS)` builds the app and the `ContainersCore` framework it embeds. -- `ContainersCoreTests` runs the framework's tests. The app target has no tests. +- `Containers (macOS)` builds the app and the `ContainersCore` framework it embeds, and runs all the project's tests. Add new test targets to this scheme's test action. +- `ContainersCoreTests` runs only the framework's tests. The app target has no tests yet. Signing reads `DEVELOPMENT_TEAM` from `Configuration/Local.xcconfig`, which is ignored by git. Copy `Configuration/Local.xcconfig.example` and fill in a team ID. @@ -16,7 +16,7 @@ xcodebuild -project Containers.xcodeproj -scheme 'Containers (macOS)' build ``` ```bash -xcodebuild -project Containers.xcodeproj -scheme ContainersCoreTests test +xcodebuild -project Containers.xcodeproj -scheme 'Containers (macOS)' -destination 'platform=macOS' test ``` ```bash @@ -117,8 +117,10 @@ Rules for where logic goes: ## Releases -- To release, set `MARKETING_VERSION` (such as `0.2`), then push a tag with that number on `main`. `containers-testflight.yml` checks that the tag is on `main` and matches the version, then uploads the build to TestFlight. -- Release notes are the What's New text in App Store Connect; the repository keeps no changelog. Once a version is live, run `containers-release.yml` from the Actions tab; it publishes a GitHub release for its tag with those notes and a Mac App Store link. +- To test a build before choosing a version, run `containers-testflight.yml` from the Actions tab on any branch; it uploads the build to TestFlight with no tag or release. +- To release, set `MARKETING_VERSION` (such as `0.2`), then push a tag with that number on `main`. `containers-testflight.yml` checks that the tag is on `main`, that `containers-build.yml` passed on it and that it matches the version, uploads the final build to TestFlight, and creates a draft GitHub release for the tag. +- Release notes are written by hand in the draft release: a summary sentence, then one `- ` bullet per change with its pull requests, such as `- Create networks from the Networks tab (#7)`. The App Store What's New text and the website use the same notes without the pull requests; the repository keeps no changelog. +- Once the version is live, run `containers-release.yml` from the Actions tab; it adds a Mac App Store link to the draft's notes and publishes it. ## Requirements diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e74402a..d6641a1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -47,7 +47,7 @@ When preparing a pull request, follow this checklist: * Imitate the conventions of surrounding code. * Set your own `DEVELOPMENT_TEAM` in `Configuration/Local.xcconfig` (copy it from `Configuration/Local.xcconfig.example`) rather than in Xcode's Signing & Capabilities tab, which writes it into the project file. * Format code as described in [Formatting contributions](#formatting-contributions) (otherwise the build will fail). -* Verify that the app builds and that the unit tests pass (`xcodebuild test -project Containers.xcodeproj -scheme ContainersCoreTests -destination 'platform=macOS'`). +* Verify that the app builds and that the unit tests pass (`xcodebuild test -project Containers.xcodeproj -scheme 'Containers (macOS)' -destination 'platform=macOS'`). * If you changed the UI, add a screenshot or video to the pull request. * Follow the [seven rules](https://cbea.ms/git-commit/#seven-rules) of great Git commit messages: * Separate subject from body with a blank line.