|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + major: |
| 7 | + description: 'Major version' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + minor: |
| 11 | + description: 'Minor version' |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + patch: |
| 15 | + description: 'Patch version' |
| 16 | + required: true |
| 17 | + type: string |
| 18 | + pre: |
| 19 | + description: 'Pre-release version (leave empty for release)' |
| 20 | + required: false |
| 21 | + type: string |
| 22 | + |
| 23 | +permissions: |
| 24 | + contents: read |
| 25 | + pull-requests: read |
| 26 | + |
| 27 | +jobs: |
| 28 | + validate-inputs: |
| 29 | + name: Validate version inputs |
| 30 | + runs-on: ubuntu-latest |
| 31 | + steps: |
| 32 | + - name: Validate inputs are numeric |
| 33 | + env: |
| 34 | + MAJOR: ${{ inputs.major }} |
| 35 | + MINOR: ${{ inputs.minor }} |
| 36 | + PATCH: ${{ inputs.patch }} |
| 37 | + PRE: ${{ inputs.pre }} |
| 38 | + run: | |
| 39 | + if ! [[ "$MAJOR" =~ ^[0-9]+$ ]]; then |
| 40 | + echo "Error: major version must be numeric" |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | + if ! [[ "$MINOR" =~ ^[0-9]+$ ]]; then |
| 44 | + echo "Error: minor version must be numeric" |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | + if ! [[ "$PATCH" =~ ^[0-9]+$ ]]; then |
| 48 | + echo "Error: patch version must be numeric" |
| 49 | + exit 1 |
| 50 | + fi |
| 51 | + if [ -n "$PRE" ] && ! [[ "$PRE" =~ ^[a-zA-Z0-9.-]+$ ]]; then |
| 52 | + echo "Error: pre-release version contains invalid characters" |
| 53 | + exit 1 |
| 54 | + fi |
| 55 | +
|
| 56 | + prepare-release: |
| 57 | + name: Get current version |
| 58 | + needs: validate-inputs |
| 59 | + runs-on: ubuntu-latest |
| 60 | + outputs: |
| 61 | + current-major: ${{ steps.current-version.outputs.major }} |
| 62 | + current-minor: ${{ steps.current-version.outputs.minor }} |
| 63 | + current-patch: ${{ steps.current-version.outputs.patch }} |
| 64 | + current-pre: ${{ steps.current-version.outputs.pre }} |
| 65 | + steps: |
| 66 | + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 |
| 67 | + with: |
| 68 | + persist-credentials: false |
| 69 | + |
| 70 | + - name: Read current version |
| 71 | + id: current-version |
| 72 | + run: | |
| 73 | + major=$(grep "MAJOR = " lib/view_component/version.rb | grep -o "[0-9]\+") |
| 74 | + minor=$(grep "MINOR = " lib/view_component/version.rb | grep -o "[0-9]\+") |
| 75 | + patch=$(grep "PATCH = " lib/view_component/version.rb | grep -o "[0-9]\+") |
| 76 | + pre=$(grep "PRE = " lib/view_component/version.rb | grep -o "\"[^\"]*\"" | tr -d '"') |
| 77 | + echo "major=$major" >> $GITHUB_OUTPUT |
| 78 | + echo "minor=$minor" >> $GITHUB_OUTPUT |
| 79 | + echo "patch=$patch" >> $GITHUB_OUTPUT |
| 80 | + echo "pre=$pre" >> $GITHUB_OUTPUT |
| 81 | +
|
| 82 | + - name: Show current version |
| 83 | + env: |
| 84 | + CURRENT_MAJOR: ${{ steps.current-version.outputs.major }} |
| 85 | + CURRENT_MINOR: ${{ steps.current-version.outputs.minor }} |
| 86 | + CURRENT_PATCH: ${{ steps.current-version.outputs.patch }} |
| 87 | + CURRENT_PRE: ${{ steps.current-version.outputs.pre }} |
| 88 | + INPUT_MAJOR: ${{ inputs.major }} |
| 89 | + INPUT_MINOR: ${{ inputs.minor }} |
| 90 | + INPUT_PATCH: ${{ inputs.patch }} |
| 91 | + INPUT_PRE: ${{ inputs.pre }} |
| 92 | + run: | |
| 93 | + current="$CURRENT_MAJOR.$CURRENT_MINOR.$CURRENT_PATCH" |
| 94 | + [ -n "$CURRENT_PRE" ] && current="$current-$CURRENT_PRE" |
| 95 | + echo "Current version: $current" |
| 96 | + release="$INPUT_MAJOR.$INPUT_MINOR.$INPUT_PATCH" |
| 97 | + [ -n "$INPUT_PRE" ] && release="$release-$INPUT_PRE" |
| 98 | + echo "Release version: $release" |
| 99 | +
|
| 100 | + release: |
| 101 | + name: Create release |
| 102 | + needs: [prepare-release, validate-inputs] |
| 103 | + runs-on: ubuntu-latest |
| 104 | + permissions: |
| 105 | + contents: write |
| 106 | + pull-requests: write |
| 107 | + steps: |
| 108 | + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 |
| 109 | + with: |
| 110 | + fetch-depth: 0 |
| 111 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 112 | + persist-credentials: false |
| 113 | + |
| 114 | + - name: Set up Ruby |
| 115 | + uses: ruby/setup-ruby@95ef2b042f9d7a56d8268cba8559e2842e2ad01b |
| 116 | + with: |
| 117 | + bundler-cache: true |
| 118 | + |
| 119 | + - name: Configure git |
| 120 | + run: | |
| 121 | + git config user.name "github-actions[bot]" |
| 122 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 123 | +
|
| 124 | + - name: Create release |
| 125 | + env: |
| 126 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 127 | + MAJOR: ${{ inputs.major }} |
| 128 | + MINOR: ${{ inputs.minor }} |
| 129 | + PATCH: ${{ inputs.patch }} |
| 130 | + PRE: ${{ inputs.pre }} |
| 131 | + run: | |
| 132 | + script/release "$MAJOR" "$MINOR" "$PATCH" "$PRE" |
0 commit comments