name: release-plugin on: push: tags: - "plugins-*-*-v*.*.*" - "!plugins-destination-duckdb-v*.*.*" - "!plugins-destination-sqlite-v*.*.*" - "!plugins-destination-snowflake-v*.*.*" - "!plugins-source-test-v*.*.*" jobs: prepare: runs-on: ubuntu-latest outputs: plugin_name: ${{ steps.split.outputs.plugin_name }} plugin_type: ${{ steps.split.outputs.plugin_type }} plugin_version: ${{ steps.split.outputs.plugin_version }} plugin_dir: ${{ steps.split.outputs.plugin_dir }} prerelease: ${{ steps.semver_parser.outputs.prerelease }} plugin_releaser: ${{ steps.set-result.outputs.result }} steps: - name: Split tag id: split run: | tag=${{ github.ref_name }} plugin_type=$(echo $tag | cut -d- -f2) plugin_name=$(echo $tag | cut -d- -f3) plugin_version=$(echo $tag | cut -d- -f4-) # perform looping till either the plugin version passes our semver test or is empty until [[ $plugin_version =~ ^v?[0-9]+\.[0-9]+ ]] || [[ $(echo $plugin_version | wc -c) -eq 0 ]] ; do echo "${plugin_version} is not a valid version" plugin_name="$plugin_name-$(echo $plugin_version | cut -d- -f1)" plugin_version=$(echo $plugin_version | cut -d- -f2-) done echo "plugin_name=${plugin_name}" >> $GITHUB_OUTPUT echo "plugin_type=${plugin_type}" >> $GITHUB_OUTPUT echo "plugin_version=${plugin_version}" >> $GITHUB_OUTPUT echo "plugin_dir=plugins/${plugin_type}/${plugin_name}" >> $GITHUB_OUTPUT # Fail if not a valid SemVer string - name: Parse semver string uses: booxmedialtd/ws-action-parse-semver@7784200024d6b3fc01253e617ec0168daf603de3 id: semver_parser with: input_string: ${{steps.split.outputs.plugin_version}} - name: Checkout uses: actions/checkout@v4 - uses: actions/github-script@v7 id: set-result env: PLUGIN_DIR: ${{steps.split.outputs.plugin_dir}} with: script: | const fs = require('fs').promises; const path = require('path'); const pluginFiles = await fs.readdir(process.env.PLUGIN_DIR); if (pluginFiles.includes('Dockerfile')) { return 'docker'; } if (pluginFiles.includes('.goreleaser.yaml')) { return 'go'; } result-encoding: string release-plugin-docker: permissions: contents: read packages: write timeout-minutes: 60 runs-on: ubuntu-latest needs: prepare if: needs.prepare.outputs.plugin_releaser == 'docker' env: IMAGE_NAME_PREFIX: cloudquery REGISTRY: ghcr.io steps: - name: Log in to the Container registry uses: docker/login-action@5139682d94efc37792e6b54386b5b470a68a4737 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@0d103c3126aa41d772a8362f6aa67afac040f80c - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@232fc64e3a4e54539e087c5976439ea54be0959d with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_PREFIX }}/cq-${{ needs.prepare.outputs.plugin_type }}-${{ needs.prepare.outputs.plugin_name }} - name: Build and push Docker image uses: docker/build-push-action@831ca179d3cf91cf0c90ca465a408fa61e2129a2 env: BUILDX_NO_DEFAULT_ATTESTATIONS: 1 with: context: "{{defaultContext}}:${{ needs.prepare.outputs.plugin_dir }}" platforms: linux/amd64,linux/arm64 push: true tags: | ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_PREFIX }}/cq-${{ needs.prepare.outputs.plugin_type }}-${{ needs.prepare.outputs.plugin_name }}:latest ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_PREFIX }}/cq-${{ needs.prepare.outputs.plugin_type }}-${{ needs.prepare.outputs.plugin_name }}:${{ needs.prepare.outputs.plugin_version }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max build-args: | GITHUB_ACTOR=${{ github.actor }} GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} - name: Checkout uses: actions/checkout@v4 - name: Update version file if: needs.prepare.outputs.prerelease == '' run: 'echo "{ \"latest\": \"${{github.ref_name}}\" }" > ./website/versions/${{needs.prepare.outputs.plugin_type}}-${{needs.prepare.outputs.plugin_name}}.json' - name: Create Pull Request if: needs.prepare.outputs.prerelease == '' uses: peter-evans/create-pull-request@v4 with: # required so the PR triggers workflow runs token: ${{ secrets.GH_CQ_BOT }} branch: chore/update-plugin-${{needs.prepare.outputs.plugin_type}}-${{needs.prepare.outputs.plugin_name}}-version base: main title: "chore: Update plugin `${{needs.prepare.outputs.plugin_type}}-${{needs.prepare.outputs.plugin_name}}` version to ${{needs.prepare.outputs.plugin_version}}" commit-message: "chore: Update plugin `${{needs.prepare.outputs.plugin_type}}-${{needs.prepare.outputs.plugin_name}}` version to ${{needs.prepare.outputs.plugin_version}}" body: Updates the `${{needs.prepare.outputs.plugin_type}}-${{needs.prepare.outputs.plugin_name}}` plugin latest version to ${{needs.prepare.outputs.plugin_version}} labels: automerge author: cq-bot release-plugin-go: timeout-minutes: 60 runs-on: ubuntu-latest needs: prepare if: needs.prepare.outputs.plugin_releaser == 'go' env: CGO_ENABLED: 0 steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 2 - uses: actions/cache@v4 with: path: | ~/.cache/go-build ~/go/pkg/mod key: ${{ runner.os }}-go-1.22.4-release-cache-${{ hashFiles(format('{0}/{1}', needs.prepare.outputs.plugin_dir, 'go.sum')) }} restore-keys: | ${{ runner.os }}-go-1.22.4-release-cache-plugins-${{ needs.prepare.outputs.plugin_type }}-${{ needs.prepare.outputs.plugin_name }} - name: Set up Go 1.x uses: actions/setup-go@v5 with: go-version-file: ${{needs.prepare.outputs.plugin_dir}}/go.mod cache: false - name: Install GoReleaser uses: goreleaser/goreleaser-action@v5 with: distribution: goreleaser-pro version: latest install-only: true - name: Run GoReleaser Dry-Run run: goreleaser release --timeout 50m --clean --skip=validate,publish,sign -f ./${{needs.prepare.outputs.plugin_dir}}/.goreleaser.yaml env: GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} GORELEASER_CURRENT_TAG: ${{ github.ref_name }} - name: Run GoReleaser run: goreleaser release --timeout 50m --clean -f ./${{needs.prepare.outputs.plugin_dir}}/.goreleaser.yaml env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} GORELEASER_CURRENT_TAG: ${{ github.ref_name }} - name: Update version file if: needs.prepare.outputs.prerelease == '' run: 'echo "{ \"latest\": \"${{github.ref_name}}\" }" > ./website/versions/${{needs.prepare.outputs.plugin_type}}-${{needs.prepare.outputs.plugin_name}}.json' - name: Create Pull Request if: needs.prepare.outputs.prerelease == '' uses: peter-evans/create-pull-request@v4 with: # required so the PR triggers workflow runs token: ${{ secrets.GH_CQ_BOT }} branch: chore/update-plugin-${{needs.prepare.outputs.plugin_type}}-${{needs.prepare.outputs.plugin_name}}-version base: main title: "chore: Update plugin `${{needs.prepare.outputs.plugin_type}}-${{needs.prepare.outputs.plugin_name}}` version to ${{needs.prepare.outputs.plugin_version}}" commit-message: "chore: Update plugin `${{needs.prepare.outputs.plugin_type}}-${{needs.prepare.outputs.plugin_name}}` version to ${{needs.prepare.outputs.plugin_version}}" body: Updates the `${{needs.prepare.outputs.plugin_type}}-${{needs.prepare.outputs.plugin_name}}` plugin latest version to ${{needs.prepare.outputs.plugin_version}} labels: automerge author: cq-bot