Check tls-client version #228
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Check tls-client version | |
| on: | |
| schedule: | |
| - cron: '0 0 * * *' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| check-tls-client-version: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v4 | |
| - name: Install dependencies | |
| run: | | |
| pwd | |
| sudo apt-get update | |
| sudo apt-get install -y jq gh tree | |
| - name: Get latest release info | |
| id: get_latest | |
| run: | | |
| RELEASE_JSON=$(curl -s https://api.github.com/repos/bogdanfinn/tls-client/releases/latest) | |
| TAG_NAME=$(echo "$RELEASE_JSON" | jq -r '.tag_name') | |
| echo "Latest tag: $TAG_NAME" | |
| echo "LATEST_TAG=$TAG_NAME" >> $GITHUB_ENV | |
| - name: Check if new version | |
| id: check_version | |
| run: | | |
| if [ -f "./tls-client-version.txt" ]; then | |
| LAST_VERSION=$(cat ./tls-client-version.txt) | |
| else | |
| LAST_VERSION="" | |
| fi | |
| echo "Last processed version: $LAST_VERSION" | |
| if [ "$LAST_VERSION" = "${{ env.LATEST_TAG }}" ]; then | |
| echo "Already up to date. Exiting." | |
| echo "SHOULD_CONTINUE=false" >> $GITHUB_ENV | |
| else | |
| echo "New version found: ${{ env.LATEST_TAG }}" | |
| echo "SHOULD_CONTINUE=true" >> $GITHUB_ENV | |
| fi | |
| - name: Download tls-client libraries | |
| if: env.SHOULD_CONTINUE == 'true' | |
| run: | | |
| # Create temp directory for downloads | |
| mkdir -p build/temp | |
| # Use the already fetched latest release info | |
| echo "Downloading assets from latest release: ${{ env.LATEST_TAG }}" | |
| # Get assets for the latest release using GitHub CLI | |
| assets=$(gh release view ${{ env.LATEST_TAG }} --repo bogdanfinn/tls-client --json assets -q '.assets[].name' | grep -v "xgo") | |
| for asset in $assets; do | |
| echo "Downloading $asset..." | |
| # Download the asset directly using GitHub CLI | |
| gh release download ${{ env.LATEST_TAG }} --repo bogdanfinn/tls-client --pattern "$asset" --dir build/temp | |
| if [ $? -eq 0 ]; then | |
| echo "Downloaded $asset successfully" | |
| else | |
| echo "Failed to download $asset" | |
| fi | |
| done | |
| # List downloaded files | |
| echo "Downloaded files in build/temp:" | |
| ls -la build/temp/ | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Update version file | |
| if: env.SHOULD_CONTINUE == 'true' | |
| run: | | |
| echo "${{ env.LATEST_TAG }}" > tls-client-version.txt | |
| echo "Updated version file to ${{ env.LATEST_TAG }}" | |
| - name: Setup Node.js | |
| if: env.SHOULD_CONTINUE == 'true' | |
| uses: actions/[email protected] | |
| with: | |
| node-version: 'latest' | |
| - name: Run native-builder script | |
| if: env.SHOULD_CONTINUE == 'true' | |
| run: | | |
| # Pass the version to the Node.js script via environment variable | |
| export TLS_CLIENT_VERSION="${{ env.LATEST_TAG }}" | |
| # Run the prepare script | |
| cd build/native-builder | |
| npm install | |
| npm run prepare-libraries | |
| echo "Native libraries preparation completed" | |
| # Return to root directory | |
| cd ../.. | |
| # Remove template directory after projects are generated | |
| rm -rf src/native/template | |
| - name: Setup .NET | |
| if: env.SHOULD_CONTINUE == 'true' | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: 8.0.x | |
| - name: Pack and publish native projects to NuGet | |
| if: env.SHOULD_CONTINUE == 'true' | |
| run: | | |
| # Extract version number from LATEST_TAG (remove 'v' prefix) | |
| VERSION="${{ env.LATEST_TAG }}" | |
| if [[ "$VERSION" == v* ]]; then | |
| VERSION="${VERSION#v}" | |
| fi | |
| echo "Using version: $VERSION for all native packages" | |
| # Create output directory | |
| mkdir -p packages | |
| # Find all .csproj files in native directories | |
| for project in src/native/TlsClient.Native.*/*.csproj; do | |
| echo "Packing project: $project" | |
| # Pack the project with the extracted version | |
| dotnet pack "$project" -c Release -p:Version=$VERSION --output packages | |
| if [ $? -ne 0 ]; then | |
| echo "Warning: Packaging failed for $project" | |
| continue | |
| fi | |
| # Get the package name from the project file name | |
| package_name=$(basename "$project" .csproj) | |
| package_path="packages/$package_name.$VERSION.nupkg" | |
| if [ -f "$package_path" ]; then | |
| # Push to NuGet | |
| echo "Publishing package: $package_path" | |
| dotnet nuget push "$package_path" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate | |
| else | |
| echo "Warning: Package not found at $package_path" | |
| fi | |
| done | |
| env: | |
| NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} | |
| - name: Commit and push changes | |
| if: env.SHOULD_CONTINUE == 'true' | |
| run: | | |
| git config --global user.name "GitHub Actions" | |
| git config --global user.email "[email protected]" | |
| git add tls-client-version.txt | |
| git commit -m "Update tls-client version to ${{ env.LATEST_TAG }}" | |
| git push |