Skip to content

Commit 8cc20ae

Browse files
authored
Merge pull request #412 from Permify/omer/auto-release
feat: auto publish with permify tag
2 parents 10d3b8f + 5777254 commit 8cc20ae

7 files changed

Lines changed: 116 additions & 8 deletions

File tree

.github/workflows/auto-release.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Auto Release
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
paths:
9+
- 'package.json'
10+
- 'package-lock.json'
11+
- 'proto/**'
12+
- 'src/**'
13+
14+
permissions:
15+
contents: write
16+
17+
jobs:
18+
release:
19+
name: Create SDK Release
20+
timeout-minutes: 10
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- name: Harden Runner
25+
uses: step-security/harden-runner@df199fb7be9f65074067a9eb93f12bb4c5547cf2 # v2.13.3
26+
with:
27+
egress-policy: audit
28+
29+
- name: Checkout repository
30+
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
31+
with:
32+
fetch-depth: 0
33+
34+
- name: Create tag and release
35+
env:
36+
GH_TOKEN: ${{ secrets.PAT_TOKEN }}
37+
run: |
38+
PACKAGE_VERSION="$(sed -n 's/^[[:space:]]*"version":[[:space:]]*"\([^"]*\)".*/\1/p' package.json | head -n 1)"
39+
40+
if [ -z "${PACKAGE_VERSION}" ]; then
41+
echo "Package version is empty. Skipping release creation."
42+
exit 0
43+
fi
44+
45+
TAG_NAME="v${PACKAGE_VERSION}"
46+
47+
if git rev-parse -q --verify "refs/tags/${TAG_NAME}" >/dev/null; then
48+
echo "Tag ${TAG_NAME} already exists. Skipping release creation."
49+
exit 0
50+
fi
51+
52+
echo "Creating release ${TAG_NAME}"
53+
git config --global user.name "GitHub Actions Bot"
54+
git config --global user.email "<>"
55+
git tag -a "${TAG_NAME}" -m "Release ${TAG_NAME}"
56+
git push origin "${TAG_NAME}"
57+
58+
gh release create "${TAG_NAME}" \
59+
--repo "${GITHUB_REPOSITORY}" \
60+
--title "${TAG_NAME}" \
61+
--generate-notes

.github/workflows/protos.yml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
name: Update Permify Proto Definitions
22

33
on:
4-
push:
5-
branches: [ "main" ]
64
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "Release version from the Permify repo (for example v1.6.9)"
8+
required: false
9+
type: string
710

811
permissions:
912
contents: write
@@ -66,6 +69,18 @@ jobs:
6669
- name: Generate Code with Buf
6770
run: yarn buf:generate
6871

72+
- name: Write package version
73+
if: ${{ github.event.inputs.version != '' }}
74+
run: npm version "${VERSION#v}" --no-git-tag-version --allow-same-version
75+
env:
76+
VERSION: ${{ github.event.inputs.version }}
77+
78+
- name: Build
79+
run: yarn build
80+
81+
- name: Run tests
82+
run: yarn run-instance
83+
6984
- name: Commit changes
7085
id: commitchanges
7186
run: |
@@ -91,6 +106,17 @@ jobs:
91106
if [ -n "${PR_NUMBER}" ]; then
92107
gh pr edit "${PR_NUMBER}" --title "${PR_TITLE}" --body "${PR_BODY}"
93108
else
94-
gh pr create --base main --head "${BRANCH_NAME}" --title "${PR_TITLE}" --body "${PR_BODY}" --label dependencies --label automated
109+
CREATE_ARGS=(--base main --head "${BRANCH_NAME}" --title "${PR_TITLE}" --body "${PR_BODY}")
110+
LABELS="$(gh label list --json name --jq '.[].name' || true)"
111+
112+
if printf '%s\n' "${LABELS}" | grep -qx 'dependencies'; then
113+
CREATE_ARGS+=(--label dependencies)
114+
fi
115+
116+
if printf '%s\n' "${LABELS}" | grep -qx 'automated'; then
117+
CREATE_ARGS+=(--label automated)
118+
fi
119+
120+
gh pr create "${CREATE_ARGS[@]}"
95121
fi
96122
shell: bash

.github/workflows/publish.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@ jobs:
2929

3030
- name: Build
3131
run: yarn build
32+
33+
- name: Run tests
34+
run: yarn run-instance
3235

3336
- name: Write release version
3437
run: |
3538
VERSION=${GITHUB_REF_NAME#v}
3639
echo Version: $VERSION
3740
echo "VERSION=$VERSION" >> $GITHUB_ENV
3841
39-
- run: "npm version ${VERSION} --no-git-tag-version"
42+
- run: "npm version ${VERSION} --no-git-tag-version --allow-same-version"
4043

4144
- name: Publish to NPM
4245
run: npm publish --access public

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
services:
22
permify:
3-
image: "ghcr.io/permify/permify:v1.5.0"
3+
image: "ghcr.io/permify/permify:v1.6.9"
44
ports: ['3478:3478']
55
command: "serve"

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
],
1414
"scripts": {
1515
"run-instance": "scripts/run-instance.sh",
16+
"test": "yarn run-test",
1617
"run-test": "ts-node node_modules/jasmine/bin/jasmine --config=jasmine.json",
1718
"lint": "eslint \"src/**/*.ts\"",
1819
"build": "rm -rf ./dist && npx tsc && cp -r src/grpc/generated dist/src/grpc/",

scripts/commit-changes.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -euo pipefail
44

55
branch_name="${1:?branch name is required}"
66

7-
if git diff --quiet; then
7+
if [[ -z "$(git status --porcelain)" ]]; then
88
echo "changes_made=0" >> "${GITHUB_OUTPUT}"
99
echo "No changes detected"
1010
exit 0

scripts/run-instance.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,25 @@
22

33
set -e
44

5+
ROOT_DIR="$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)"
6+
57
exit_code=0
6-
docker compose up -d --wait
7-
yarn run || exit_code=$?
8+
cd "${ROOT_DIR}"
9+
10+
docker compose up -d
11+
12+
for attempt in $(seq 1 60); do
13+
if nc -z 127.0.0.1 3478 >/dev/null 2>&1; then
14+
yarn run-test || exit_code=$?
15+
break
16+
fi
17+
sleep 1
18+
done
19+
20+
if [ "${exit_code}" -eq 0 ] && ! nc -z 127.0.0.1 3478 >/dev/null 2>&1; then
21+
echo "Permify did not become reachable on 127.0.0.1:3478 within 60 seconds." >&2
22+
exit_code=1
23+
fi
24+
825
docker compose down
926
exit $exit_code

0 commit comments

Comments
 (0)