From 63a3579ee66ececf6aeebc1fb606d48b6680944a Mon Sep 17 00:00:00 2001 From: Anatolios Laskaris Date: Wed, 15 Feb 2023 16:45:04 +0200 Subject: [PATCH] chore: Add release-please (#240) * Add release-please * Fix * Fix ci.js * Rename fluence-js * Run pnpm i * Fix * Update workflows * Fix --- .github/actionlint.yaml | 3 + .github/release-please/config.json | 18 ++ .github/release-please/manifest.json | 8 + .github/workflows/changelog_config.json | 5 - .github/workflows/e2e.yml.disabled | 10 ++ .github/workflows/lint.yml | 35 ++++ .github/workflows/release.yml | 168 ++++++++++++++++++ .../{tests.yml.disabled => run-tests.yml} | 64 +++---- .../{snapshot.yml.disabled => snapshot.yml} | 0 .github/workflows/tests.yml | 107 +++++++---- ci.js | 9 +- pnpm-workspace.yaml | 1 - 12 files changed, 344 insertions(+), 84 deletions(-) create mode 100644 .github/actionlint.yaml create mode 100644 .github/release-please/config.json create mode 100644 .github/release-please/manifest.json delete mode 100644 .github/workflows/changelog_config.json create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/release.yml rename .github/workflows/{tests.yml.disabled => run-tests.yml} (55%) rename .github/workflows/{snapshot.yml.disabled => snapshot.yml} (100%) diff --git a/.github/actionlint.yaml b/.github/actionlint.yaml new file mode 100644 index 00000000..be1bfdcd --- /dev/null +++ b/.github/actionlint.yaml @@ -0,0 +1,3 @@ +self-hosted-runner: + labels: + - builder diff --git a/.github/release-please/config.json b/.github/release-please/config.json new file mode 100644 index 00000000..f73e3f4e --- /dev/null +++ b/.github/release-please/config.json @@ -0,0 +1,18 @@ +{ + "release-type": "node", + "bump-minor-pre-major": true, + "bump-patch-for-minor-pre-major": true, + "plugins": [ + { + "type": "node-workspace" + } + ], + "packages": { + "packages/client/api": {}, + "packages/js-client.node": {}, + "packages/js-client.web.standalone": {}, + "packages/tools": {}, + "packages/core/interfaces": {}, + "packages/core/js-peer": {} + } +} diff --git a/.github/release-please/manifest.json b/.github/release-please/manifest.json new file mode 100644 index 00000000..c7ec0830 --- /dev/null +++ b/.github/release-please/manifest.json @@ -0,0 +1,8 @@ +{ + "packages/client/api": "0.10.0", + "packages/js-client.node": "0.5.0", + "packages/js-client.web.standalone": "0.12.0", + "packages/tools": "0.1.0", + "packages/core/interfaces": "0.6.0", + "packages/core/js-peer": "0.7.0" +} diff --git a/.github/workflows/changelog_config.json b/.github/workflows/changelog_config.json deleted file mode 100644 index 9d01d64a..00000000 --- a/.github/workflows/changelog_config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "template": "${{CHANGELOG}}\n\n${{UNCATEGORIZED}}", - "pr_template": "- #${{NUMBER}} ${{TITLE}}", - "empty_template": "- no changes" -} diff --git a/.github/workflows/e2e.yml.disabled b/.github/workflows/e2e.yml.disabled index d8ef1960..3c29d740 100644 --- a/.github/workflows/e2e.yml.disabled +++ b/.github/workflows/e2e.yml.disabled @@ -4,9 +4,19 @@ on: pull_request: paths-ignore: - "**.md" + - ".github/**" + - "!.github/workflows/e2e.yml" + - "!.github/workflows/tests.yml" + - "!.github/workflows/snapshot.yml" push: branches: - "master" + paths-ignore: + - "**.md" + - ".github/**" + - "!.github/workflows/e2e.yml" + - "!.github/workflows/tests.yml" + - "!.github/workflows/snapshot.yml" concurrency: group: "${{ github.workflow }}-${{ github.ref }}" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..b3374a52 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,35 @@ +name: lint + +on: + pull_request: + types: + - opened + - edited + - synchronize + +concurrency: + group: "${{ github.workflow }}-${{ github.ref }}" + cancel-in-progress: true + +jobs: + pr: + name: Validate PR title + runs-on: ubuntu-latest + steps: + - uses: amannn/action-semantic-pull-request@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + reviewdog: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Lint actions + uses: reviewdog/action-actionlint@v1 + env: + SHELLCHECK_OPTS: "-e SC2086 -e SC2207 -e SC2128" + with: + reporter: github-pr-check + fail_on_error: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..73e60079 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,168 @@ +name: "release-please" + +on: + push: + branches: + - "master" + +concurrency: + group: "${{ github.workflow }}-${{ github.ref }}" + +env: + CI: true + FORCE_COLOR: true + +jobs: + release-please: + runs-on: ubuntu-latest + + outputs: + release-created: ${{ steps.release.outputs.releases_created }} + pr: ${{ steps.release.outputs.pr }} + + steps: + - name: Run release-please + id: release + uses: google-github-actions/release-please-action@v3 + with: + token: ${{ secrets.FLUENCEBOT_RELEASE_PLEASE_PAT }} + command: manifest + config-file: .github/release-please/config.json + manifest-file: .github/release-please/manifest.json + + - name: Show output from release-please + if: steps.release.outputs.releases_created + env: + RELEASE_PLEASE_OUTPUT: ${{ toJSON(steps.release.outputs) }} + run: echo "${RELEASE_PLEASE_OUTPUT}" | jq + + bump-version: + if: needs.release-please.outputs.pr != null + runs-on: ubuntu-latest + needs: + - release-please + + permissions: + contents: write + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + ref: ${{ fromJson(needs.release-please.outputs.pr).headBranchName }} + token: ${{ secrets.FLUENCEBOT_RELEASE_PLEASE_PAT }} + + - name: Setup pnpm + uses: pnpm/action-setup@v2.2.4 + with: + version: 7 + + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version: "18" + registry-url: "https://registry.npmjs.org" + cache: "pnpm" + + - run: pnpm i --no-frozen-lockfile + + - name: Commit version bump + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "chore: Regenerate pnpm lock file" + branch: ${{ fromJson(needs.release-please.outputs.pr).headBranchName }} + commit_user_name: fluencebot + commit_user_email: devops@fluence.one + commit_author: fluencebot + + fluence-js: + if: needs.release-please.outputs.release-created + runs-on: ubuntu-latest + needs: + - release-please + + permissions: + contents: read + id-token: write + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Import secrets + uses: hashicorp/vault-action@v2.4.3 + with: + url: https://vault.fluence.dev + path: jwt/github + role: ci + method: jwt + jwtGithubAudience: "https://github.com/fluencelabs" + jwtTtl: 300 + exportToken: false + secrets: | + kv/npmjs/fluencebot token | NODE_AUTH_TOKEN + + - name: Setup pnpm + uses: pnpm/action-setup@v2.2.4 + with: + version: 7 + + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version: "18" + registry-url: "https://registry.npmjs.org" + cache: "pnpm" + + - run: pnpm i + - run: pnpm -r build + + - name: Publish to npm registry + run: pnpm --no-git-checks -r publish -filter '@fluencelabs/*' --access public --tags unstable + + slack: + if: always() + name: "Notify" + runs-on: ubuntu-latest + + needs: + - release-please + - fluence-js + + permissions: + contents: read + id-token: write + + steps: + - uses: lwhiteley/dependent-jobs-result-check@v1 + id: status + with: + statuses: failure + dependencies: ${{ toJSON(needs) }} + + - name: Log output + run: | + echo "statuses:" "${{ steps.status.outputs.statuses }}" + echo "jobs:" "${{ steps.status.outputs.jobs }}" + echo "found any?:" "${{ steps.status.outputs.found }}" + + - name: Import secrets + uses: hashicorp/vault-action@v2.4.3 + with: + url: https://vault.fluence.dev + path: jwt/github + role: ci + method: jwt + jwtGithubAudience: "https://github.com/fluencelabs" + jwtTtl: 300 + exportToken: false + secrets: | + kv/slack/release-please webhook | SLACK_WEBHOOK_URL + + - uses: ravsamhq/notify-slack-action@v2 + if: steps.status.outputs.found == 'true' + with: + status: "failure" + notification_title: "*{workflow}* has {status_message}" + message_format: "${{ steps.status.outputs.jobs }} {status_message} in <{repo_url}|{repo}>" + footer: "<{run_url}>" diff --git a/.github/workflows/tests.yml.disabled b/.github/workflows/run-tests.yml similarity index 55% rename from .github/workflows/tests.yml.disabled rename to .github/workflows/run-tests.yml index a1078069..3d9d590e 100644 --- a/.github/workflows/tests.yml.disabled +++ b/.github/workflows/run-tests.yml @@ -1,27 +1,29 @@ -name: Run tests with worflow_call +name: "ci" on: - workflow_call: - inputs: - rust-peer-image: - description: "rust-peer image tag" - type: string - default: "fluencelabs/fluence:minimal" - avm-version: - description: "@fluencelabs/avm version" - type: string - default: "null" - marine-js-version: - description: "@fluencelabs/marine-js version" - type: string - default: "null" - ref: - description: "git ref to checkout to" - type: string - default: "master" + pull_request: + paths-ignore: + - "**.md" + - ".github/**" + - "!.github/workflows/e2e.yml" + - "!.github/workflows/tests.yml" + - "!.github/workflows/snapshot.yml" + push: + branches: + - "master" + paths-ignore: + - "**.md" + - ".github/**" + - "!.github/workflows/e2e.yml" + - "!.github/workflows/tests.yml" + - "!.github/workflows/snapshot.yml" + +concurrency: + group: "${{ github.workflow }}-${{ github.ref }}" + cancel-in-progress: true env: - RUST_PEER_IMAGE: "${{ inputs.rust-peer-image }}" + RUST_PEER_IMAGE: "fluencelabs/fluence:minimal" FORCE_COLOR: true CI: true @@ -39,6 +41,7 @@ jobs: node-version: - 16.x - 17.x + - 18.x steps: - name: Import secrets @@ -63,9 +66,6 @@ jobs: - name: Checkout uses: actions/checkout@v3 - with: - repository: fluencelabs/fluence-js - ref: ${{ inputs.ref }} - name: Pull rust-peer image run: docker pull $RUST_PEER_IMAGE @@ -90,23 +90,5 @@ jobs: - run: pnpm i - - name: Set avm version - if: inputs.avm-version != 'null' - uses: fluencelabs/github-actions/npm-set-dependency@main - with: - package: "@fluencelabs/avm" - version: ${{ inputs.avm-version }} - working-directory: packages/fluence-js - package-manager: pnpm - - - name: Set marine-js version - if: inputs.marine-js-version != 'null' - uses: fluencelabs/github-actions/npm-set-dependency@main - with: - package: "@fluencelabs/marine-js" - version: ${{ inputs.marine-js-version }} - working-directory: packages/fluence-js - package-manager: pnpm - - run: pnpm -r build - run: pnpm -r test diff --git a/.github/workflows/snapshot.yml.disabled b/.github/workflows/snapshot.yml similarity index 100% rename from .github/workflows/snapshot.yml.disabled rename to .github/workflows/snapshot.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0963d3dd..a1078069 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,8 +1,4 @@ -name: Run tests - -defaults: - run: - working-directory: . +name: Run tests with worflow_call on: workflow_call: @@ -22,7 +18,7 @@ on: ref: description: "git ref to checkout to" type: string - default: "v0.28.0" + default: "master" env: RUST_PEER_IMAGE: "${{ inputs.rust-peer-image }}" @@ -34,32 +30,83 @@ jobs: name: "Run tests" runs-on: ubuntu-latest - strategy: - matrix: - node-version: [16.x, 17.x, 18.x] + permissions: + contents: read + id-token: write - steps: - - uses: actions/checkout@v2 + strategy: + matrix: + node-version: + - 16.x + - 17.x - - name: Setup Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} + steps: + - name: Import secrets + uses: hashicorp/vault-action@v2.4.3 + with: + url: https://vault.fluence.dev + path: jwt/github + role: ci + method: jwt + jwtGithubAudience: "https://github.com/fluencelabs" + jwtTtl: 300 + secrets: | + kv/docker-registry/basicauth/ci username | DOCKER_USERNAME ; + kv/docker-registry/basicauth/ci password | DOCKER_PASSWORD - - name: Setup pnpm - uses: pnpm/action-setup@v2.2.4 - with: - version: 7 + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + registry: docker.fluence.dev + username: ${{ env.DOCKER_USERNAME }} + password: ${{ env.DOCKER_PASSWORD }} - - name: Run container with Fluence node - run: | - docker pull fluencelabs/fluence - docker run -d --rm -e RUST_LOG="info" -p 1210:1210 -p 4310:4310 fluencelabs/fluence -t 1210 -w 4310 -k gKdiCSUr1TFGFEgu2t8Ch1XEUsrN5A2UfBLjSZvfci9SPR3NvZpACfcpPGC3eY4zma1pk7UvYv5zb1VjvPHwCjj --local --aqua-pool-size 2 + - name: Checkout + uses: actions/checkout@v3 + with: + repository: fluencelabs/fluence-js + ref: ${{ inputs.ref }} - - run: pnpm i - - run: pnpm -r build - env: - CI: true - - run: pnpm -r test - env: - CI: true + - name: Pull rust-peer image + run: docker pull $RUST_PEER_IMAGE + + - name: Run rust-peer + uses: isbang/compose-action@v1.4.1 + with: + compose-file: ".github/e2e/docker-compose.yml" + down-flags: "--volumes" + + - name: Setup pnpm + uses: pnpm/action-setup@v2.2.4 + with: + version: 7 + + - name: Setup node ${{ matrix.node-version }} with self-hosted registry + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + registry-url: "https://npm.fluence.dev" + cache: "pnpm" + + - run: pnpm i + + - name: Set avm version + if: inputs.avm-version != 'null' + uses: fluencelabs/github-actions/npm-set-dependency@main + with: + package: "@fluencelabs/avm" + version: ${{ inputs.avm-version }} + working-directory: packages/fluence-js + package-manager: pnpm + + - name: Set marine-js version + if: inputs.marine-js-version != 'null' + uses: fluencelabs/github-actions/npm-set-dependency@main + with: + package: "@fluencelabs/marine-js" + version: ${{ inputs.marine-js-version }} + working-directory: packages/fluence-js + package-manager: pnpm + + - run: pnpm -r build + - run: pnpm -r test diff --git a/ci.js b/ci.js index 8df67322..bf4bc821 100644 --- a/ci.js +++ b/ci.js @@ -74,12 +74,7 @@ function processDep(obj, name, fn) { return; } - if (!/^workspace\:/.test(obj[name])) { - return; - } - - const version = obj[name].replace("workspace:", ""); - fn(obj, version); + fn(obj, obj[name]); } async function getVersionsMap(allPackageJsons) { return new Map(await Promise.all(allPackageJsons.map(getVersion))); @@ -125,7 +120,7 @@ async function bumpVersions(file, versionsMap) { // bump dependencies for (const [name, version] of versionsMap) { - const update = (x) => (x[name] = `workspace:${version}-${postfix}`); + const update = (x) => (x[name] = `${version}-${postfix}`); processDep(json.dependencies, name, update); processDep(json.devDependencies, name, update); } diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 0e66a78d..5858666e 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,3 +1,2 @@ - packages: - 'packages/**/*'