|
| 1 | +# Copyright (C) 2025 Red Hat, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# |
| 15 | +# SPDX-License-Identifier: Apache-2.0 |
| 16 | + |
| 17 | +name: 'Fetch Latest Podman Version for Windows' |
| 18 | +description: 'Fetches the latest Podman release version and constructs Windows download URLs' |
| 19 | + |
| 20 | +inputs: |
| 21 | + version_input: |
| 22 | + description: 'Version input - use "latest" to auto-fetch, or provide specific version' |
| 23 | + required: true |
| 24 | + default: 'latest' |
| 25 | + architecture: |
| 26 | + description: 'Architecture for Windows (amd64, arm64)' |
| 27 | + required: false |
| 28 | + default: 'amd64' |
| 29 | + file_type: |
| 30 | + description: 'File type for Windows (setup.exe, installer.exe, remote.zip)' |
| 31 | + required: false |
| 32 | + default: 'setup.exe' |
| 33 | + |
| 34 | +outputs: |
| 35 | + version: |
| 36 | + description: 'The Podman version (e.g., v5.6.1)' |
| 37 | + value: ${{ steps.fetch.outputs.version }} |
| 38 | + download_url: |
| 39 | + description: 'The constructed download URL' |
| 40 | + value: ${{ steps.fetch.outputs.download_url }} |
| 41 | + is_latest: |
| 42 | + description: 'Whether the latest version was fetched (true/false)' |
| 43 | + value: ${{ steps.fetch.outputs.is_latest }} |
| 44 | + |
| 45 | +runs: |
| 46 | + using: 'composite' |
| 47 | + steps: |
| 48 | + - name: Fetch Podman version and construct URL |
| 49 | + id: fetch |
| 50 | + shell: bash |
| 51 | + run: | |
| 52 | + INPUT_VERSION="${{ inputs.version_input }}" |
| 53 | + ARCHITECTURE="${{ inputs.architecture }}" |
| 54 | + FILE_TYPE="${{ inputs.file_type }}" |
| 55 | + |
| 56 | + echo "Input version: $INPUT_VERSION" |
| 57 | + echo "Architecture: $ARCHITECTURE" |
| 58 | + echo "File type: $FILE_TYPE" |
| 59 | + |
| 60 | + # Input validation |
| 61 | + if [ -z "$INPUT_VERSION" ]; then |
| 62 | + echo "Error: Version input cannot be empty" |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | + |
| 66 | + if [ "$INPUT_VERSION" = "latest" ]; then |
| 67 | + echo "Fetching latest Podman release..." |
| 68 | + |
| 69 | + # Check if jq is available |
| 70 | + if ! command -v jq &> /dev/null; then |
| 71 | + echo "Error: jq is required but not installed" |
| 72 | + exit 1 |
| 73 | + fi |
| 74 | + |
| 75 | + # Fetch latest release with error handling |
| 76 | + API_RESPONSE=$(curl -s https://api.github.com/repos/containers/podman/releases/latest) |
| 77 | + if [ $? -ne 0 ]; then |
| 78 | + echo "Error: Failed to fetch data from GitHub API" |
| 79 | + exit 1 |
| 80 | + fi |
| 81 | + |
| 82 | + # Check for API errors (rate limiting, etc.) |
| 83 | + if echo "$API_RESPONSE" | jq -e '.message' >/dev/null 2>&1; then |
| 84 | + ERROR_MESSAGE=$(echo "$API_RESPONSE" | jq -r '.message') |
| 85 | + echo "Error: GitHub API returned an error: $ERROR_MESSAGE" |
| 86 | + exit 1 |
| 87 | + fi |
| 88 | + |
| 89 | + # Parse version with validation |
| 90 | + LATEST_VERSION=$(echo "$API_RESPONSE" | jq -r '.tag_name') |
| 91 | + if [ "$LATEST_VERSION" = "null" ] || [ -z "$LATEST_VERSION" ]; then |
| 92 | + echo "Error: Could not parse version from GitHub API response" |
| 93 | + exit 1 |
| 94 | + fi |
| 95 | + |
| 96 | + echo "Latest Podman version: $LATEST_VERSION" |
| 97 | + echo "version=$LATEST_VERSION" >> $GITHUB_OUTPUT |
| 98 | + echo "is_latest=true" >> $GITHUB_OUTPUT |
| 99 | + VERSION_NUMBER=${LATEST_VERSION#v} |
| 100 | + elif [[ "$INPUT_VERSION" =~ ^https?:// ]]; then |
| 101 | + # Full URL provided, use as-is |
| 102 | + echo "Full URL provided: $INPUT_VERSION" |
| 103 | + echo "download_url=$INPUT_VERSION" >> $GITHUB_OUTPUT |
| 104 | + echo "is_latest=false" >> $GITHUB_OUTPUT |
| 105 | + # Try to extract version from URL for version output |
| 106 | + if [[ "$INPUT_VERSION" =~ v([0-9]+\.[0-9]+\.[0-9]+) ]]; then |
| 107 | + echo "version=v${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT |
| 108 | + else |
| 109 | + echo "version=custom" >> $GITHUB_OUTPUT |
| 110 | + fi |
| 111 | + exit 0 |
| 112 | + else |
| 113 | + # Specific version provided |
| 114 | + echo "Specific version provided: $INPUT_VERSION" |
| 115 | + |
| 116 | + # Validate version format (should be semver-like: v5.6.1, 5.6.1, v5.6.1-rc1, etc.) |
| 117 | + if [[ ! "$INPUT_VERSION" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+([.-](rc|alpha|beta)[0-9]*)?$ ]]; then |
| 118 | + echo "Error: Invalid version format: $INPUT_VERSION" |
| 119 | + echo "Expected formats: v5.6.1, 5.6.1, v5.6.1-rc1, 5.6.1-rc1, etc." |
| 120 | + exit 1 |
| 121 | + fi |
| 122 | + |
| 123 | + if [[ "$INPUT_VERSION" =~ ^v ]]; then |
| 124 | + LATEST_VERSION="$INPUT_VERSION" |
| 125 | + else |
| 126 | + LATEST_VERSION="v$INPUT_VERSION" |
| 127 | + fi |
| 128 | + echo "version=$LATEST_VERSION" >> $GITHUB_OUTPUT |
| 129 | + echo "is_latest=false" >> $GITHUB_OUTPUT |
| 130 | + VERSION_NUMBER=${LATEST_VERSION#v} |
| 131 | + fi |
| 132 | + |
| 133 | + # Construct Windows download URL |
| 134 | + case "$FILE_TYPE" in |
| 135 | + "setup.exe") |
| 136 | + DOWNLOAD_URL="https://github.com/containers/podman/releases/download/${LATEST_VERSION}/podman-${VERSION_NUMBER}-setup.exe" |
| 137 | + ;; |
| 138 | + "installer.exe") |
| 139 | + DOWNLOAD_URL="https://github.com/containers/podman/releases/download/${LATEST_VERSION}/podman-installer-windows-${ARCHITECTURE}.exe" |
| 140 | + ;; |
| 141 | + "remote.zip") |
| 142 | + DOWNLOAD_URL="https://github.com/containers/podman/releases/download/${LATEST_VERSION}/podman-remote-release-windows_${ARCHITECTURE}.zip" |
| 143 | + ;; |
| 144 | + *) |
| 145 | + echo "Error: Unsupported Windows file type: $FILE_TYPE" |
| 146 | + echo "Supported types: setup.exe, installer.exe, remote.zip" |
| 147 | + exit 1 |
| 148 | + ;; |
| 149 | + esac |
| 150 | + |
| 151 | + echo "Download URL: $DOWNLOAD_URL" |
| 152 | + |
| 153 | + # Validate that the download URL actually exists |
| 154 | + echo "Validating download URL..." |
| 155 | + HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -I "$DOWNLOAD_URL") |
| 156 | + if [ "$HTTP_CODE" != "200" ] && [ "$HTTP_CODE" != "302" ]; then |
| 157 | + echo "Error: Download file not found (HTTP $HTTP_CODE)" |
| 158 | + echo "URL: $DOWNLOAD_URL" |
| 159 | + echo "This may indicate the version doesn't exist or the file type isn't available for this version" |
| 160 | + exit 1 |
| 161 | + fi |
| 162 | + |
| 163 | + echo "Download URL validated successfully" |
| 164 | + echo "download_url=$DOWNLOAD_URL" >> $GITHUB_OUTPUT |
0 commit comments