diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..c6e120f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,122 @@ +name: Release Modules + +on: + workflow_dispatch: + inputs: + validation_version: + description: 'Validation module version (e.g., v0.1.0) - leave empty to skip' + required: false + type: string + playground_version: + description: 'Playground module version (e.g., v0.1.0)' + required: true + type: string + +permissions: + contents: write + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.24' + + - name: Validate version formats + run: | + if [[ -n "${{ inputs.validation_version }}" ]] && [[ ! "${{ inputs.validation_version }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Error: validation_version must be in format vX.Y.Z" + exit 1 + fi + if [[ ! "${{ inputs.playground_version }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Error: playground_version must be in format vX.Y.Z" + exit 1 + fi + + - name: Check if validation tag already exists + if: inputs.validation_version != '' + run: | + if git rev-parse "validation/${{ inputs.validation_version }}" >/dev/null 2>&1; then + echo "Error: Tag validation/${{ inputs.validation_version }} already exists" + exit 1 + fi + + - name: Check if playground tag already exists + run: | + if git rev-parse "playground/${{ inputs.playground_version }}" >/dev/null 2>&1; then + echo "Error: Tag playground/${{ inputs.playground_version }} already exists" + exit 1 + fi + + - name: Create validation module release + if: inputs.validation_version != '' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release create "validation/${{ inputs.validation_version }}" \ + --title "validation ${{ inputs.validation_version }}" \ + --notes "Release of validation module ${{ inputs.validation_version }}" \ + --target ${{ github.ref_name }} + + - name: Update playground go.mod with new validation version + if: inputs.validation_version != '' + run: | + cd playground + + # Update the validation dependency version + go get github.com/quantumcycle/protego/validation@${{ inputs.validation_version }} + + # Remove replace directive if it exists + if grep -q "^replace github.com/quantumcycle/protego/validation" go.mod; then + sed -i '/^replace github.com\/quantumcycle\/protego\/validation/d' go.mod + fi + + go mod tidy + + - name: Commit and push playground go.mod changes + if: inputs.validation_version != '' + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + git add playground/go.mod playground/go.sum + + if git diff --staged --quiet; then + echo "No changes to commit" + else + git commit -m "chore(playground): update validation dependency to ${{ inputs.validation_version }}" + git push origin ${{ github.ref_name }} + fi + + - name: Create playground module release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Get the latest commit (which may include go.mod update if validation was released) + LATEST_COMMIT=$(git rev-parse HEAD) + + gh release create "playground/${{ inputs.playground_version }}" \ + --title "playground ${{ inputs.playground_version }}" \ + --notes "Release of playground module ${{ inputs.playground_version }}" \ + --target $LATEST_COMMIT + + - name: Summary + run: | + echo "✅ Successfully released modules:" + if [[ -n "${{ inputs.validation_version }}" ]]; then + echo " - validation/${{ inputs.validation_version }}" + fi + echo " - playground/${{ inputs.playground_version }}" + echo "" + echo "Users can now install with:" + if [[ -n "${{ inputs.validation_version }}" ]]; then + echo " go get github.com/quantumcycle/protego/validation@${{ inputs.validation_version }}" + fi + echo " go get github.com/quantumcycle/protego/playground@${{ inputs.playground_version }}"