From d73dc844425999c69e4f416ce29fd94c15507087 Mon Sep 17 00:00:00 2001 From: Anatolios Laskaris Date: Wed, 12 Apr 2023 19:58:32 +0300 Subject: [PATCH] chore(ci): Add release-please (#5) Add release-please --- .github/release-please/config.json | 10 +++ .github/release-please/manifest.json | 3 + .github/workflows/lint.yml | 35 ++++++++ .github/workflows/publish_release.yml | 73 ---------------- .github/workflows/release.yml | 121 ++++++++++++++++++++++++++ 5 files changed, 169 insertions(+), 73 deletions(-) create mode 100644 .github/release-please/config.json create mode 100644 .github/release-please/manifest.json create mode 100644 .github/workflows/lint.yml delete mode 100644 .github/workflows/publish_release.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/release-please/config.json b/.github/release-please/config.json new file mode 100644 index 0000000..15531b1 --- /dev/null +++ b/.github/release-please/config.json @@ -0,0 +1,10 @@ +{ + "release-type": "node", + "bump-minor-pre-major": true, + "bump-patch-for-minor-pre-major": true, + "packages": { + ".": { + "component": "fluence-network-environment" + } + } +} diff --git a/.github/release-please/manifest.json b/.github/release-please/manifest.json new file mode 100644 index 0000000..28180e9 --- /dev/null +++ b/.github/release-please/manifest.json @@ -0,0 +1,3 @@ +{ + ".": "1.0.14" +} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..9342c28 --- /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" + with: + reporter: github-pr-check + fail_on_error: true diff --git a/.github/workflows/publish_release.yml b/.github/workflows/publish_release.yml deleted file mode 100644 index 6ec6e1c..0000000 --- a/.github/workflows/publish_release.yml +++ /dev/null @@ -1,73 +0,0 @@ -name: "publish-release" - -on: - push: - branches: - - "main" - -jobs: - npm-publish: - name: "Publish" - runs-on: ubuntu-latest - defaults: - run: - shell: bash - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - ### Calculate FINAL_VERSION - - name: Install jq - run: sudo apt-get update && sudo apt-get --yes --force-yes install jq - - - name: Get version from npm and increment - run: | - set -x - yarn global add semver - PATH="$(yarn global bin):$PATH" - - # take npm version and increment it - PKG_NAME="$(cat package.json | jq -r .name)" - NPM_VERSION="$(yarn info --silent "$PKG_NAME" version || true)" - NEXT_NPM_VERSION="$(semver --increment patch "$NPM_VERSION")" - - # take local version - LOCAL_VERSION="$(cat package.json | jq -r .version)" - - # take maximum of the local and NEXT_NPM versions - MAX_VERSION="$(semver "$LOCAL_VERSION" "$NEXT_NPM_VERSION" "0.0.0" | tail -n1)" - - # save version to env - echo "FINAL_VERSION=$MAX_VERSION" | tee -a $GITHUB_ENV - - ### Set version - - name: Set version to ${{ env.FINAL_VERSION }} - run: yarn version --new-version ${{ env.FINAL_VERSION }} --no-git-tag-version - - ### Publish to NPM registry - - uses: actions/setup-node@v1 - with: - node-version: '14' - registry-url: 'https://registry.npmjs.org' - - - run: npm i - - run: npm run build - - - run: npm publish --access public - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - - ### Create a pre-release - - name: Create Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ env.FINAL_VERSION }} - release_name: Fluence Network ${{ env.FINAL_VERSION }} - body: | - [${{ env.FINAL_VERSION }} @ NPM registry](https://www.npmjs.com/package/@fluencelabs/fluence-network-environment/v/${{ env.FINAL_VERSION }}) - draft: false - prerelease: false \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..30bdf46 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,121 @@ +name: "release-please" + +on: + push: + branches: + - "main" + +concurrency: + group: "${{ github.workflow }}-${{ github.ref }}" + +jobs: + release-please: + runs-on: ubuntu-latest + + outputs: + releases-created: ${{ steps.release.outputs.releases_created }} + + package-release-created: ${{ steps.release.outputs['release_created'] }} + package-tag-name: ${{ steps.release.outputs['tag_name'] }} + + 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 + + package: + if: needs.release-please.outputs.releases-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.5.0 + 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 node + uses: actions/setup-node@v3 + with: + node-version: "16" + registry-url: "https://registry.npmjs.org" + cache: "npm" + + - run: npm i + + - name: Publish to npm registry + run: npm publish --access public + + slack: + if: always() + name: "Notify" + runs-on: ubuntu-latest + + needs: + - release-please + - package + + 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.5.0 + 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}>"