From 9a05734ba1e49971f105c88f2a3a0528ddb96e1e Mon Sep 17 00:00:00 2001 From: Kevin Tchang Date: Wed, 25 Sep 2024 08:29:18 +1000 Subject: [PATCH] use version commit to update plugin version test use Github token missed one now test with changeset hardcode changeset remote branch for testing revert testing --- .github/workflows/create-versioning-pr.yaml | 72 +++++++++++++++++++++ .github/workflows/release.yaml | 15 ++--- 2 files changed, 79 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/create-versioning-pr.yaml diff --git a/.github/workflows/create-versioning-pr.yaml b/.github/workflows/create-versioning-pr.yaml new file mode 100644 index 0000000..0299d28 --- /dev/null +++ b/.github/workflows/create-versioning-pr.yaml @@ -0,0 +1,72 @@ +name: Version Plugin + +on: + push: + branches: + - 'main' + +jobs: + version: + runs-on: ubuntu-latest + + # For all pushes that aren't creating a versioning commit + if: ${{ !startsWith(github.event.commits[0].message, 'Version Helm Plugin') }} + steps: + - uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - name: setup-node + uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Cache .pnpm-store + uses: actions/cache@v3.2.3 + with: + path: ~/.pnpm-store + key: ${{ runner.os }}-node${{ matrix.node-version }}-${{ hashFiles('**/pnpm-lock.yaml') }} + + - uses: pnpm/action-setup@v4 + with: + version: 9.11.0 + run_install: true + + - name: Install YQ + uses: dcarbone/install-yq-action@v1.1.1 + + - name: Create Release Pull Request + id: changesets + uses: changesets/action@v1 + with: + commit: 'Version Helm Plugin' + title: 'Version Helm Plugin' + createGitHubReleases: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Determine whether version has changed + id: changed_packages + run: | + packageVersion=$(yq -r .version package.json) + pluginVersion=$(yq -r .version plugin.yaml) + + if [[ "packageVersion" != "pluginVersion" ]]; then + echo "pluginChanged=true" >> $GITHUB_OUTPUT + fi + if: steps.changesets.outputs.hasChangesets == 'true' + + - name: 'Update version in plugin.yaml' + run: | + version=$(yq -r .version package.json) + version="$version" yq -i '.version = strenv(version)' plugin.yaml + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git config user.name "github-actions[bot]" + git add plugin.yaml + git commit -m "Update plugin version in plugin.yaml" + if: steps.changesets.outputs.hasChangesets == 'true' && steps.changed_packages.outputs.pluginChanged == 'true' + + - name: 'Push changes' + run: | + git push --set-upstream origin changeset-release/main + if: steps.changesets.outputs.hasChangesets == 'true' \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 953a649..0f3d4c0 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -2,8 +2,8 @@ name: Release on: push: - tags: - - '*' + branches: + - 'main' permissions: contents: write @@ -11,19 +11,18 @@ permissions: jobs: goreleaser: runs-on: ubuntu-latest + + if: ${{ startsWith(github.event.commits[0].message, 'Version Helm Plugin') }} steps: - - - name: Checkout + - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 - - - name: Set up Go + - name: Set up Go uses: actions/setup-go@v5 with: go-version-file: 'go.mod' - - - name: Run GoReleaser + - name: Run GoReleaser uses: goreleaser/goreleaser-action@v6 with: distribution: goreleaser