Skip to content

Commit 8b8be80

Browse files
Merge pull request #14 from ipdata/auto-release
Release automatically when the version changes
2 parents 200e34c + b886c6e commit 8b8be80

3 files changed

Lines changed: 62 additions & 0 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,54 @@ jobs:
5353

5454
- name: Run tests
5555
run: ./vendor/bin/phpunit
56+
57+
release:
58+
name: Release
59+
needs:
60+
- build-lowest-version
61+
- build
62+
if: github.event_name == 'push' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
63+
runs-on: ubuntu-latest
64+
permissions:
65+
contents: write
66+
concurrency:
67+
group: release
68+
cancel-in-progress: false
69+
outputs:
70+
tag: ${{ steps.version.outputs.tag }}
71+
created: ${{ steps.release.outputs.created }}
72+
73+
steps:
74+
- name: Checkout code
75+
uses: actions/checkout@v7
76+
77+
- name: Read the version from the changelog
78+
id: version
79+
run: |
80+
version=$(sed -nE 's/^## ([0-9][^[:space:]]*).*/\1/p' CHANGELOG.md | head -1)
81+
if [ -z "$version" ]; then
82+
echo "::error file=CHANGELOG.md::No '## x.y.z' heading found in CHANGELOG.md"
83+
exit 1
84+
fi
85+
echo "tag=$version" >> "$GITHUB_OUTPUT"
86+
echo "The changelog version is $version; the tag is $version."
87+
88+
- name: Create the tag and the GitHub release
89+
id: release
90+
env:
91+
GH_TOKEN: ${{ github.token }}
92+
TAG: ${{ steps.version.outputs.tag }}
93+
run: |
94+
rc=0
95+
git ls-remote --exit-code --tags origin "refs/tags/$TAG" >/dev/null || rc=$?
96+
if [ "$rc" -eq 0 ]; then
97+
echo "Tag $TAG already exists; nothing to release."
98+
echo "created=false" >> "$GITHUB_OUTPUT"
99+
exit 0
100+
elif [ "$rc" -ne 2 ]; then
101+
echo "::error::Could not check whether tag $TAG exists (git ls-remote exited with $rc)."
102+
exit "$rc"
103+
fi
104+
gh release create "$TAG" --target "$GITHUB_SHA" --title "$TAG" --generate-notes
105+
echo "created=true" >> "$GITHUB_OUTPUT"
106+
echo "Created tag $TAG and its GitHub release from $GITHUB_SHA."

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Documentation and tests for the new API response fields: top-level `is_satellite` and `is_anycast` (present only when `true`) and `first_seen`, `last_seen` (`YYYY-MM-DD`, UTC) and `days_seen` on `threat.blocklists` entries (absent for some feeds). The client passes them through unchanged.
1010
- Every request carries a `User-Agent: ipdata-php/<version>` header. The version is the installed version of `ipdata/api-client` as recorded by Composer (`Composer\InstalledVersions`, Composer 2 and newer); without it the header is `ipdata-php`.
1111
- `Ipdata::DEFAULT_BASE_URL` is public, so the trailing `$httpVersion` argument can be passed without repeating the endpoint: `new Ipdata('my_api_key', $httpClient, $psr17Factory, Ipdata::DEFAULT_BASE_URL, '2.0')`.
12+
- Releases are cut by CI: when a merge to `master` puts a new `## x.y.z` heading at the top of this file, the `release` job of the CI workflow creates the tag `x.y.z` and the GitHub release, and Packagist picks the tag up through its GitHub hook (see "Releasing" in the README).
1213

1314
### Fixed
1415

‎README.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,13 @@ Some feeds, for example ipdata's own vpn feed, carry none of the three blocklist
245245
## Errors
246246

247247
A list of possible errors is available at [Status Codes](https://docs.ipdata.co/api-reference/status-codes)
248+
249+
## Releasing
250+
251+
Releases are cut by CI, and the version source is the first `## x.y.z` heading in `CHANGELOG.md`: `composer.json`
252+
carries no `version` field, and Packagist reads the versions of `ipdata/api-client` from the Git tags.
253+
254+
To release, add a `## x.y.z` heading with the release notes at the top of `CHANGELOG.md` in a pull request and merge
255+
it. On the push to `master`, once the tests have passed, the `release` job of the CI workflow tags the merge commit
256+
`x.y.z`, creates the GitHub release with generated notes, and Packagist picks the new tag up through its GitHub hook.
257+
A merge whose version is already tagged publishes nothing, so there is no manual tagging.

0 commit comments

Comments
 (0)