|
| 1 | +name: Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version_type: |
| 7 | + description: "The type of the release" |
| 8 | + required: true |
| 9 | + type: choice |
| 10 | + options: |
| 11 | + - major |
| 12 | + - minor |
| 13 | + - patch |
| 14 | + push: |
| 15 | + |
| 16 | +jobs: |
| 17 | + deploy: |
| 18 | + name: Deploy |
| 19 | + runs-on: ubuntu-latest |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout code |
| 23 | + uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - name: Update version |
| 26 | + run: | |
| 27 | + exit 1 |
| 28 | + |
| 29 | + current_version=$(grep -oP 'const PluginVersion = "\K[0-9]+\.[0-9]+\.[0-9]+' internal/core/constants.go) |
| 30 | + |
| 31 | + if [[ -z "$current_version" ]]; then |
| 32 | + echo "Error: Unable to find PluginVersion" |
| 33 | + exit 1 |
| 34 | + fi |
| 35 | + |
| 36 | + IFS='.' read -r MAJOR MINOR PATCH <<< "$current_version" |
| 37 | + |
| 38 | + if [[ "${{ inputs.version_type }}" == "major" ]]; then |
| 39 | + ((MAJOR++)) |
| 40 | + MINOR=0 |
| 41 | + PATCH=0 |
| 42 | + elif [[ "${{ inputs.version_type }}" == "minor" ]]; then |
| 43 | + ((MINOR++)) |
| 44 | + PATCH=0 |
| 45 | + elif [[ "${{ inputs.version_type }}" == "patch" ]]; then |
| 46 | + ((PATCH++)) |
| 47 | + else |
| 48 | + echo "Error: Invalid version type. Use 'major', 'minor', or 'patch'." |
| 49 | + exit 1 |
| 50 | + fi |
| 51 | + |
| 52 | + new_version="$MAJOR.$MINOR.$PATCH" |
| 53 | + echo "new plugin version is: $new_version" |
| 54 | + |
| 55 | + sed -i "s/const PluginVersion = \"[0-9]\+\.[0-9]\+\.[0-9]\+\"/const PluginVersion = \"$new_version\"/" internal/core/constants.go |
| 56 | + |
| 57 | + echo "VERSION=v$new_version" >> $GITHUB_OUTPUT |
| 58 | +
|
| 59 | + - name: Commit Changes |
| 60 | + uses: stefanzweifel/git-auto-commit-action@v5 |
| 61 | + with: |
| 62 | + commit_message: "Bump version for release" |
| 63 | + file_pattern: "internal/core/*.go" |
| 64 | + |
| 65 | + - name: Setup Go |
| 66 | + uses: actions/setup-go@v5 |
| 67 | + with: |
| 68 | + go-version-file: './go.mod' |
| 69 | + |
| 70 | + - name: Build plugin |
| 71 | + working-directory: plugin |
| 72 | + run: GOOS=wasip1 GOARCH=wasm go build -o ../tests/sqlc-gen-java.wasm |
| 73 | + |
| 74 | + - name: Create tag |
| 75 | + run: | |
| 76 | + git tag ${{ steps.update-version.outputs.VERSION }} |
| 77 | + git push origin ${{ steps.update-version.outputs.VERSION }} |
| 78 | +
|
| 79 | + - name: Generate release description |
| 80 | + run: | |
| 81 | + export checksum=$(sha256sum sqlc-gen-java.wasm | awk '{print $1}') |
| 82 | + export download_url="https://github.com/tandemdude/releases/download/${{ steps.update-version.outputs.VERSION }}/sqlc-gen-java.wasm" |
| 83 | + |
| 84 | + yq -i '.plugins[0].wasm.url = env(download_url)' .github/release_output_template.yaml |
| 85 | + yq -i '.plugins[0].wasm.sha256 = env(checksum)' .github/release_output_template.yaml |
| 86 | +
|
| 87 | + echo "\`\`\`yaml" > release_body.md |
| 88 | + cat .github/release_output_template.yaml >> release_body.md |
| 89 | + echo "\`\`\`" >> release_body.md |
| 90 | +
|
| 91 | + - name: Create release |
| 92 | + uses: softprops/action-gh-release@v2 |
| 93 | + with: |
| 94 | + token: "${{ secrets.GITHUB_TOKEN }}" |
| 95 | + name: "${{ steps.update-version.outputs.VERSION }}" |
| 96 | + tag_name: "refs/tags/${{ steps.update-version.outputs.VERSION }}" |
| 97 | + body_path: release_body.md |
| 98 | + files: sqlc-gen-java.wasm |
0 commit comments