Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Check
on:
pull_request:
permissions:
contents: read
concurrency:
group: check-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
test:
runs-on: macos-15-intel # arm64 Mac runners are short; queued jobs are dropped after 15 min
timeout-minutes: 15
env:
DEVELOPER_DIR: /Applications/Xcode_16.4.app/Contents/Developer
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
persist-credentials: false
- name: Source and release checks
run: |
python3 scripts/check-release.py
python3 -m unittest discover -s Tests/ReleaseTests
- name: Host tests
run: swift test -j 2
73 changes: 73 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Publish
# A new version in VERSION releases itself: on every push to main, if its
# vX.Y.Z tag does not exist yet, the Release workflow builds this commit,
# tags it and publishes the release. Otherwise nothing runs.
on:
push:
branches: [main]
permissions:
contents: read
concurrency:
group: publish-main
cancel-in-progress: false
jobs:
version:
runs-on: ubuntu-24.04
timeout-minutes: 3
outputs:
tag: ${{ steps.check.outputs.tag }}
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
persist-credentials: false
sparse-checkout: VERSION
sparse-checkout-cone-mode: false
- name: Is VERSION released?
id: check
env:
GH_TOKEN: ${{ github.token }}
run: |
version=$(tr -d '[:space:]' < VERSION)
if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "VERSION must be X.Y.Z, not '$version'." >&2
exit 1
fi
tag="v$version"
gh api "repos/$GITHUB_REPOSITORY/git/matching-refs/tags/$tag" --jq '.[].ref' > "$RUNNER_TEMP/refs.txt"
if grep -Fxq "refs/tags/$tag" "$RUNNER_TEMP/refs.txt"; then
echo "$tag exists; nothing to release."
tag=''
fi
echo "tag=$tag" >> "$GITHUB_OUTPUT"
release:
needs: version
if: needs.version.outputs.tag != ''
uses: ./.github/workflows/release.yml
with:
version: ${{ needs.version.outputs.tag }}
from_main: true
permissions:
contents: write
id-token: write
attestations: write
artifact-metadata: write
# Fails the run when a release was due but any of its jobs failed, was
# cancelled or skipped, or the release is not published.
published:
needs: [version, release]
if: always() && needs.version.outputs.tag != ''
runs-on: ubuntu-24.04
timeout-minutes: 2
env:
GH_TOKEN: ${{ github.token }}
RESULT: ${{ needs.release.result }}
TAG: ${{ needs.version.outputs.tag }}
steps:
- run: |
if [[ "$RESULT" != success ]]; then
echo "Release $TAG: $RESULT; nothing published." >&2
exit 1
fi
gh release view "$TAG" --repo "$GITHUB_REPOSITORY" --json isDraft,isPrerelease,assets \
--jq '"draft=\(.isDraft) prerelease=\(.isPrerelease) assets=\(.assets | length)"' | tee "$RUNNER_TEMP/release.txt"
grep -q '^draft=false prerelease=false assets=[1-9]' "$RUNNER_TEMP/release.txt"
24 changes: 19 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ on:
description: Package version (private runs retain a draft release)
required: true
default: preview
workflow_call: # from publish.yml when VERSION changes on main
inputs:
version:
description: Release tag (vX.Y.Z) to create at this commit
type: string
required: true
from_main:
type: boolean
default: false
permissions:
contents: read
concurrency:
Expand All @@ -25,7 +34,8 @@ jobs:
release_kind: ${{ steps.plan.outputs.release_kind }}
attest: ${{ steps.plan.outputs.attest }}
env:
VERSION: ${{ github.event_name == 'push' && github.ref_name || inputs.version }}
VERSION: ${{ inputs.version || github.ref_name }}
FROM_MAIN: ${{ inputs.from_main }}
REPOSITORY_PRIVATE: ${{ github.event.repository.private }}
DEVELOPER_DIR: /Applications/Xcode_16.4.app/Contents/Developer
HOMEBREW_NO_AUTO_UPDATE: '1'
Expand Down Expand Up @@ -152,18 +162,22 @@ jobs:
path: out/releases/*
if-no-files-found: error
retention-days: 2
- name: Retain draft release
# Published only here, after every job above succeeded, with all assets
# in one call (gh uploads them to a draft and publishes it at the end).
- name: Publish release
if: needs.app.outputs.release_tag != ''
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ needs.app.outputs.release_tag }}
RELEASE_KIND: ${{ needs.app.outputs.release_kind }}
run: |
options=(--repo "$GITHUB_REPOSITORY" --target "$GITHUB_SHA" --draft
options=(--repo "$GITHUB_REPOSITORY" --target "$GITHUB_SHA"
--title "Resize APFS $VERSION")
if [[ "$RELEASE_KIND" == private-preview ]]; then
options+=(--prerelease --notes "Private validation build from $GITHUB_SHA. No artifact attestation was generated.")
options+=(--draft --prerelease --notes "Private validation build from $GITHUB_SHA. No artifact attestation was generated.")
else
options+=(--verify-tag --generate-notes)
# A pushed tag must exist already; from main, this creates it at $GITHUB_SHA.
if [[ "$GITHUB_REF" == refs/tags/* ]]; then options+=(--verify-tag); fi
options+=(--latest --generate-notes)
fi
gh release create "$RELEASE_TAG" out/releases/* "${options[@]}"
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ Open `ResizeAPFS.xcodeproj`, or run `./scripts/run-simulator.sh`. Host tests:
`./scripts/build-device-ios12.sh` and `./scripts/package-release.sh preview`.
Details: [Device/README.md](Device/README.md).

Pull requests are checked with the host tests (`Check` workflow). To release, raise
the version in `VERSION` in a pull request. When it is merged, the `Publish` workflow
builds that commit, tags it `vX.Y.Z` and publishes the release with all assets, as
the latest, in about 15 minutes. A push to `main` whose version is already tagged
releases nothing. A hand-pushed `v*` tag still builds and publishes as before.

## License

[MIT](LICENSE). See [third-party notices](THIRD_PARTY_NOTICES.md).
Expand Down
16 changes: 16 additions & 0 deletions Tests/ReleaseTests/test_release_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ def test_manual_run_on_tag_is_not_a_tag_push(self):
p = module.plan('workflow_dispatch', 'preview', 'true', 'refs/tags/v0.1.0', '126')
self.assertEqual(p['release_tag'], 'private-preview-126')

def test_version_on_main_releases_its_tag(self):
p = module.plan('push', 'v0.4.9', 'false', 'refs/heads/main', '127', 'true')
self.assertEqual(p['release_tag'], 'v0.4.9')
self.assertEqual(p['release_kind'], 'release')
self.assertEqual(p['attest'], 'true')

def test_release_from_main_needs_main_and_a_plain_version(self):
for args in [
('push', 'v0.4.9', 'false', 'refs/heads/other', '127', 'true'),
('workflow_dispatch', 'v0.4.9', 'false', 'refs/heads/main', '127', 'true'),
('push', 'preview', 'false', 'refs/heads/main', '127', 'true'),
('push', '0.4.9', 'false', 'refs/heads/main', '127', 'true'),
]:
with self.subTest(args=args), self.assertRaises(ValueError):
module.plan(*args)

def test_invalid_inputs_fail_before_building(self):
for args in [
('push', 'preview', 'true', 'refs/heads/main', '123'),
Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.4.8
12 changes: 9 additions & 3 deletions scripts/release-plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@
import re


def plan(event, version, private, ref, run_id):
def plan(event, version, private, ref, run_id, from_main=''):
if not re.fullmatch(r'[A-Za-z0-9][A-Za-z0-9._-]*', version):
raise ValueError('Invalid release version.')
if private not in {'true', 'false'}:
raise ValueError('Repository visibility must be specified.')
tag = ''
kind = 'none'
if event == 'push' and ref == 'refs/tags/' + version and version.startswith('v'):
if from_main == 'true':
# Publish workflow: VERSION changed on main; the release creates the tag.
if event != 'push' or ref != 'refs/heads/main' or not re.fullmatch(r'v\d+\.\d+\.\d+', version):
raise ValueError('Only a vX.Y.Z version pushed to main may release from main.')
tag = version
kind = 'private-preview' if private == 'true' else 'release'
elif event == 'push' and ref == 'refs/tags/' + version and version.startswith('v'):
tag = version
kind = 'private-preview' if private == 'true' else 'release'
elif event == 'workflow_dispatch':
Expand All @@ -30,7 +36,7 @@ def plan(event, version, private, ref, run_id):
try:
result = plan(os.environ.get('GITHUB_EVENT_NAME', ''), os.environ.get('VERSION', ''),
os.environ.get('REPOSITORY_PRIVATE', ''), os.environ.get('GITHUB_REF', ''),
os.environ.get('GITHUB_RUN_ID', ''))
os.environ.get('GITHUB_RUN_ID', ''), os.environ.get('FROM_MAIN', ''))
except ValueError as error:
raise SystemExit(str(error))
output = ''.join(f'{key}={value}\n' for key, value in result.items())
Expand Down
Loading