Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create test and release pipelines #28

Merged
merged 7 commits into from
Oct 16, 2024
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
44 changes: 44 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Release

on:
push:
branches:
- main
- release

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
release:
name: Release
runs-on: ubuntu-22.04
# GH Token permissions as required by semantic-release
# https://github.com/semantic-release/github?tab=readme-ov-file#github-authentication
permissions:
contents: write
issues: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Run build
run: yarn build

- name: Run test
run: yarn test

- name: Publish to NPM and create a GitHub release
run: npx semantic-release
Spikatrix marked this conversation as resolved.
Show resolved Hide resolved
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
GH_TOKEN: ${{ github.token }}
38 changes: 38 additions & 0 deletions .github/workflows/sync-main-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Sync main with release

on:
push:
branches:
- release

jobs:
sync-main-branch:
runs-on: ubuntu-22.04
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Create PR from release to main
env:
GH_TOKEN: ${{ github.token }}
run: |
# Check if a pull request already exists from release to main
pr_url=$(gh pr list --head release --base main --json url --jq '.[0].url')

if [ -n "$pr_url" ]; then
echo "PR already exists: $pr_url"
else
pr_url=$(gh pr create \
--head release \
--base main \
--title "[skip ci][skip release] Sync main with the release branch" \
--body "Auto-created pull request to merge changes from release into main."
)
echo "Created PR: $pr_url"
fi

# Attempt to merge the pull request (Fails, investigate later)
# gh pr merge "$pr_url" --merge --auto
28 changes: 28 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Test

on:
pull_request:

jobs:
test:
name: Test
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'yarn'
cache-dependency-path: '**/yarn.lock'

- name: Install dependencies
run: yarn

- name: Run build
run: yarn build

- name: Run test
run: yarn test

3 changes: 3 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"branches": [{ "name": "main", "prerelease": "beta" }, "release"]
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"build": "yarn clean && yarn compile",
"compile": "tsc -p tsconfig.json -outDir ./dist",
"test": "jest",
"prepublish": "yarn build",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove build?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prepublish script gets run whenever yarn/yarn install/yarn add is executed which was annoying. IMO, running install shouldn't trigger a build.
Upstream issue: yarnpkg/yarn#3209

"lint": "eslint \"./src/**/*.{ts,tsx}\" --max-warnings=0"
},
"dependencies": {
Expand All @@ -38,12 +37,13 @@
"@types/sha.js": "^2.4.0",
"jest": "^26.6.3",
"rimraf": "^3.0.2",
"semantic-release": "^24.1.2",
"ts-jest": "^26.5.1",
"typescript": "^4.1.5"
},
"repository": {
"type": "git",
"url": "https://github.com/ngraveio/bc-ur.git"
"url": "git+https://github.com/ngraveio/bc-ur.git"
},
"keywords": [
"bc-ur"
Expand Down
Loading