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
183 changes: 25 additions & 158 deletions .github/workflows/sync-upstream.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# .github/workflows/sync-upstream.yml
#
# Drop-in template for any Ichava icon pack that wants automated
# upstream-asset refreshes. Builds the ichava/icon-sets-sync docker image
# (the Go binary, with git, gh and Node) from the toolkit's main branch and
# opens a PR when upstream has moved.
# Weekly upstream refresh for this pack. The work is done by the reusable
# workflow in ichava/icon-sets-sync: it builds the toolkit from source at the
# pinned commit below, runs the sync headless, and opens the update pull
# request with a Refresh Bot token (REFRESH_APP_CLIENT_ID /
# REFRESH_APP_PRIVATE_KEY, org level; a private repo needs repository copies),
# so that pull request's own CI runs. A licence change upstream opens an issue
# and no pull request.
#
# A human reviews the PR diff and merges. release-please then opens the
# release PR, and its tag starts release.yml, which publishes the GitHub
# release. Packagist reads the tag and lists the new version.
#
# Required:
# Refresh Bot (REFRESH_APP_CLIENT_ID / REFRESH_APP_PRIVATE_KEY, org level; a
# private repo needs repository copies) for the push and the PR. The
# organisation does not let GITHUB_TOKEN create pull requests, so a sync PR
# opened with it fails with "GitHub Actions is not permitted to create or
# approve pull requests".
# The pin is a full commit SHA of icon-sets-sync, and `toolkit-ref` must be
# the same commit. Dependabot (github-actions) advances the `uses:` pin;
# advance `toolkit-ref` with it.

name: Sync upstream

Expand All @@ -32,154 +32,21 @@ on:
default: false

permissions:
contents: write
pull-requests: write
# The sync opens its PR with GITHUB_TOKEN, and GitHub deliberately does not
# start workflow runs for events created with that token -- so the PR arrives
# with zero checks and reads as `unstable` rather than as failing. We cannot
# trigger the normal suite from here; we can attach a real commit status.
statuses: write

concurrency:
group: sync-upstream-${{ github.repository }}
cancel-in-progress: true
contents: read

jobs:
sync:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout pack repo
uses: actions/checkout@v7
with:
fetch-depth: 0

- name: Checkout ichava/icon-sets-sync (the toolkit)
uses: actions/checkout@v7
with:
repository: ichava/icon-sets-sync
path: .icon-sets-sync
# Pin to a tag in production. Floating on main is fine for
# the cron itself -- this is the maintainer's own tooling.
ref: main

- name: Configure git identity (commits go through this name)
run: |
git config user.name "ichava-sync-bot"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

# A per-run Refresh Bot token, so the PR can be opened at all (GITHUB_TOKEN
# may not create pull requests here) and its checks start like any other.
- name: Mint the Refresh Bot token
id: app
uses: actions/create-github-app-token@v3
with:
client-id: ${{ vars.REFRESH_APP_CLIENT_ID }}
private-key: ${{ secrets.REFRESH_APP_PRIVATE_KEY }}
permission-contents: write
permission-pull-requests: write

- name: Authenticate gh for PR creation
run: gh auth setup-git
env:
GH_TOKEN: ${{ steps.app.outputs.token }}

# Build from the toolkit checkout instead of pulling ghcr.io — the
# GHCR package is private and other repos' GITHUB_TOKENs cannot pull
# it; the source is already checked out one step above.
- name: Build icon-sets-sync image
run: docker build -t icon-sets-sync:local .icon-sets-sync

- name: Run icon-sets-sync via Docker
env:
GH_TOKEN: ${{ steps.app.outputs.token }}
PACK_SLUG: ${{ github.event.repository.name }}
run: |
# An array, not a string: $FLAGS unquoted relies on word-splitting to
# expand to nothing when empty, and quoting it would pass an empty
# argument instead. "${FLAGS[@]}" does both correctly.
FLAGS=()
if [ "${{ inputs.force }}" = "true" ]; then FLAGS+=(--force); fi

# The push happens INSIDE the container. `gh auth setup-git` ran on
# the runner, and actions/checkout leaves its credential in a file
# under RUNNER_TEMP that is not mounted here, so the container had no
# way to authenticate: `git push` exited 128 at the GitBranch stage,
# after a full and successful asset refresh. Hand it the same
# Authorization header actions/checkout uses. GH_TOKEN is masked in
# logs, and so is anything derived from it.
AUTH_HEADER="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$GH_TOKEN" | base64 | tr -d '\n')"
docker run --rm \
-v "$PWD/..:/work" \
-v "$PWD/.icon-sets-sync/config:/app/config" \
-e GH_TOKEN \
-e GIT_CONFIG_COUNT=2 \
-e GIT_CONFIG_KEY_0=safe.directory \
-e GIT_CONFIG_VALUE_0='*' \
-e GIT_CONFIG_KEY_1='http.https://github.com/.extraheader' \
-e GIT_CONFIG_VALUE_1="$AUTH_HEADER" \
icon-sets-sync:local \
sync --pack="$PACK_SLUG" "${FLAGS[@]}"

# Without this the sync PR has no checks at all: see the note on
# `statuses: write` above. Run the suite against whatever the sync just
# pushed and attach the verdict to that commit, so the PR shows a real
# pass/fail instead of silence.
# The verify step runs Composer on the runner itself, so it needs the
# PHP the package requires and a token for the `vcs` repositories in
# composer.json. Without either, `composer update` fails with "Could not
# authenticate against github.com" and the suite never runs.
- name: Set up PHP for verification
if: success()
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: '8.5'
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, intl
coverage: none

- name: Verify the synced branch and report a commit status
if: success()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GITHUB_TOKEN }}"}}'
run: |
set -euo pipefail

# `gh pr list` has no prefix filter -- only exact --head -- so list
# the open PRs and select by prefix here.
PR_JSON=$(gh pr list --repo "$GITHUB_REPOSITORY" --state open \
--json number,headRefName,headRefOid --limit 50 \
--jq '[.[] | select(.headRefName | startswith("chore/sync-upstream"))]' \
2>/dev/null || echo '[]')
if [ "$(printf '%s' "$PR_JSON" | jq 'length')" -eq 0 ]; then
echo "No sync PR open -- nothing to verify."
exit 0
fi

REF=$(printf '%s' "$PR_JSON" | jq -r '.[0].headRefName')
SHA=$(printf '%s' "$PR_JSON" | jq -r '.[0].headRefOid')
echo "Verifying $REF at $SHA"

post_status() {
gh api -X POST "repos/$GITHUB_REPOSITORY/statuses/$SHA" \
-f state="$1" -f context='Sync verification' -f description="$2" \
-f target_url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >/dev/null
}

post_status pending 'Running the suite against the synced content'

git fetch origin "$REF"
git checkout -q "$SHA"

if composer update --prefer-stable --prefer-dist --no-interaction --no-progress \
&& vendor/bin/pest; then
post_status success 'Suite passed on the synced content'
else
post_status failure 'Suite failed on the synced content'
echo "::error::The synced content does not pass this package's suite. Do not merge $REF."
exit 1
fi

- name: Clean up
if: always()
run: rm -rf .icon-sets-sync
# The called workflow sets timeout-minutes and its own concurrency group.
# `issues: write` is for the licence-change issue; every write to the
# repository goes through the Refresh Bot token.
permissions:
contents: read
issues: write
uses: ichava/icon-sets-sync/.github/workflows/sync-pack.yml@5d70f5d1d258b75e9afd3e70b8036d4100ed9d7c # main 2026-11-04
with:
pack: ${{ github.event.repository.name }}
toolkit-ref: 5d70f5d1d258b75e9afd3e70b8036d4100ed9d7c
refresh-app-client-id: ${{ vars.REFRESH_APP_CLIENT_ID }}
force: ${{ inputs.force == true }}
secrets:
refresh-app-private-key: ${{ secrets.REFRESH_APP_PRIVATE_KEY }}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ All notable changes to `ichava/icon-sets-flag` follow [Keep a Changelog](https:/

### Changed

- **`sync-upstream.yml` is a caller of icon-sets-sync's reusable `sync-pack.yml`**, pinned to a full commit SHA (icon-sets-sync#79). It builds the toolkit from source at that commit instead of `docker build` from `main`, grants `GITHUB_TOKEN` only `contents: read` and `issues: write` (the `contents`, `pull-requests` and `statuses: write` grants are gone: the Refresh Bot token does the writes), and opens an issue on an upstream licence change. The in-job Pest run and commit status are dropped; the sync pull request now starts the normal CI. `tests/Unit/SyncWorkflowCallerTest.php` pins the pin, the triggers and the permissions, and `symfony/yaml` joins `require-dev` for it.

- **Documentation links point at each repository's own `docs/`** (Sim, 2026-11-03: "all ichava repos have docs in their respective repos. thats by design"). Links to `opensource.simtabi.com/documentation/ichava/...` and the `opensource.simtabi.com/products/ichava/...` homepage, which answer 404 for every ichava page, now go to the matching `docs/*.md` on GitHub, or to the repository itself. Each target was checked to exist on that repository's `main`. The manifest's `homepage` and `support.docs` follow.
- **The author and contact address is `ichava@simtabi.com`** (W-11, Sim 2026-11-03), replacing the community address `opensource@simtabi.com` wherever this repository named it. Vulnerability reports still go to `security@simtabi.com`. The test that guards the address expects `ichava@` now.

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"orchestra/testbench": "^11.0",
"pestphp/pest": "^4.6 || ^5.0",
"phpstan/phpstan": "^2.1",
"laravel/pint": "^1.18"
"laravel/pint": "^1.18",
"symfony/yaml": "^7.0 || ^8.0"
},
"autoload": {
"psr-4": {
Expand Down
7 changes: 7 additions & 0 deletions docs/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ polls `flag-icons`, refreshes the vendored SVGs, bumps `upstream.current_version
`resources/assets/svg/config.json` and opens a pull request. That pull request is the change; a
release follows it only if you want the new icons published under a tag.

The weekly refresh is `.github/workflows/sync-upstream.yml`, a caller of the reusable
[`sync-pack.yml`](https://github.com/ichava/icon-sets-sync/blob/main/.github/workflows/sync-pack.yml)
in icon-sets-sync, pinned to a commit. It builds the toolkit from source at that commit, opens the
pull request with the Refresh Bot token so the pull request's own CI runs, and on an upstream
licence change opens an issue instead of a pull request. Advance the pin (the `uses:` SHA and
`toolkit-ref`, the same commit) to take a newer toolkit.

Core's [check pack updates](https://github.com/ichava/core/blob/main/docs/recipes/check-pack-updates.md) reports whether a newer upstream
release exists. **The vendored version lives in `config.json` and nowhere else** -- writing it into
prose as well is how a README came to advertise a release the pack did not ship.
Expand Down
44 changes: 44 additions & 0 deletions tests/Unit/SyncWorkflowCallerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

use Symfony\Component\Yaml\Yaml;

/**
* The upstream sync is a caller of icon-sets-sync's reusable workflow, pinned to a
* commit, never triggered by a push, and holding only the permissions the called
* workflow needs.
*
* @return array<string, mixed>
*/
function sync_caller(): array
{
$path = dirname(__DIR__, 2) . '/.github/workflows/sync-upstream.yml';
expect(is_file($path))->toBeTrue();

return Yaml::parseFile($path);
}

it(description: 'calls the reusable sync-pack workflow pinned to a 40-hex commit', closure: function () {
$job = sync_caller()['jobs']['sync'] ?? [];

expect($job['uses'] ?? '')->toMatch('#^ichava/icon-sets-sync/\.github/workflows/sync-pack\.yml@[0-9a-f]{40}$#');
expect($job['with']['toolkit-ref'] ?? '')->toMatch('/^[0-9a-f]{40}$/');
expect(explode('@', $job['uses'])[1])->toBe($job['with']['toolkit-ref']);
});

it(description: 'runs on a schedule and a manual dispatch, never on push', closure: function () {
$on = sync_caller()['on'] ?? null;

expect($on)->toBeArray();
expect(array_keys($on))->toBe(['schedule', 'workflow_dispatch']);
expect($on['schedule'])->toHaveCount(1);
});

it(description: 'declares only the permissions the called workflow needs', closure: function () {
$workflow = sync_caller();

expect($workflow['permissions'])->toBe(['contents' => 'read']);
expect($workflow['jobs']['sync']['permissions'])->toBe(['contents' => 'read', 'issues' => 'write']);
expect(array_keys($workflow['jobs']))->toBe(['sync']);
});
Loading