2.0.2 #85
Workflow file for this run
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: Publish | |
| on: | |
| workflow_dispatch: | |
| release: | |
| types: [published] | |
| env: | |
| APP_NAME: semver | |
| jobs: | |
| version: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.parse_version.outputs.version }} | |
| major: ${{ steps.parse_version.outputs.major }} | |
| minor: ${{ steps.parse_version.outputs.minor }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: denoland/setup-deno@v2 | |
| with: | |
| deno-version: v2.x | |
| - id: parse_version | |
| name: Parse the Version | |
| run: | | |
| rm deno.lock | |
| deno install | |
| deno run -A main.ts get | |
| assets: | |
| runs-on: ubuntu-latest | |
| needs: version | |
| permissions: | |
| contents: write | |
| strategy: | |
| matrix: | |
| target: | |
| - name: "x86_64-unknown-linux-gnu" | |
| extension: "" | |
| - name: "x86_64-pc-windows-msvc" | |
| extension: ".exe" | |
| - name: "x86_64-apple-darwin" | |
| extension: "" | |
| - name: "aarch64-apple-darwin" | |
| extension: "" | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: denoland/setup-deno@v2 | |
| with: | |
| deno-version: v2.x | |
| - name: Setup | |
| run: | | |
| rm deno.lock | |
| deno install --no-lock | |
| # Binaries are compiled on full Release | |
| - name: Compile | |
| if: github.event_name == 'release' | |
| env: | |
| TARGET: ${{ matrix.target.name }} | |
| EXT: ${{ matrix.target.extension }} | |
| run: | | |
| deno compile --allow-run --allow-env --allow-read --allow-write -o bin/$APP_NAME --target $TARGET main.ts | |
| cd bin && tar -czf $APP_NAME.$TARGET.tar.gz ${APP_NAME}${EXT} | |
| ls -la | |
| - name: Upload Release Asset | |
| uses: actions/upload-release-asset@v1 | |
| if: github.event_name == 'release' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| upload_url: ${{ github.event.release.upload_url }} | |
| asset_path: ./bin/${{ env.APP_NAME }}.${{ matrix.target.name }}.tar.gz | |
| asset_name: ${{ env.APP_NAME }}.${{ matrix.target.name }}.tar.gz | |
| asset_content_type: application/tar+gzip | |
| - name: Print Output | |
| if: github.event_name == 'release' | |
| env: | |
| VERSION: ${{ needs.version.outputs.version }} | |
| TARGET: ${{ matrix.target.name }} | |
| DOWNLOAD_URL: ${{ github.event.release.download_url }} | |
| ASSET_NAME: ${{ env.APP_NAME }}.${{ matrix.target.name }}.tar.gz | |
| run: | | |
| URL="https://github.com/Optum/semver-cli/releases/download/${VERSION}/${ASSET_NAME}" | |
| SHA=$(cat ./bin/${{ env.APP_NAME}}.${{ matrix.target.name }}.tar.gz | sha256sum | cut -d " " -f1) | |
| cat >> $GITHUB_STEP_SUMMARY<<EOF | |
| | part | value | | |
| | ---------- | ------------------ | | |
| | name | \`${APP_NAME}\` | | |
| | version | \`${VERSION}\` | | |
| | target | \`${TARGET}\` | | |
| | asset | [\`${ASSET_NAME}\`]($URL) | | |
| #### formula | |
| \`\`\`rb | |
| url "$URL" | |
| sha256 "$SHA" | |
| \`\`\` | |
| EOF | |
| docker: | |
| runs-on: ubuntu-latest | |
| needs: version | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v2 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push | |
| uses: docker/build-push-action@v4 | |
| with: | |
| push: true | |
| tags: optum/semver-cli:latest,optum/semver-cli:${{ needs.version.outputs.version }},optum/semver-cli:v${{ needs.version.outputs.major }}.${{ needs.version.outputs.minor }},optum/semver-cli:v${{ needs.version.outputs.major }} | |
| platforms: linux/amd64 | |
| homebrew: | |
| if: ${{ github.event_name == 'release' && github.event.release.prerelease == false }} | |
| runs-on: ubuntu-latest | |
| needs: | |
| - version | |
| - assets | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| env: | |
| GH_TOKEN: ${{ secrets.SEMVER_PUBLISH_TOKEN }} | |
| GITHUB_TOKEN: ${{ secrets.SEMVER_PUBLISH_TOKEN }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Configure Git | |
| run: | | |
| # Configure git | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
| gh auth setup-git | |
| - name: Download Release Assets and Generate Formula | |
| env: | |
| VERSION: ${{ needs.version.outputs.version }} | |
| run: | | |
| mkdir -p assets Formula | |
| # Download each asset using GitHub CLI and calculate SHA256 | |
| declare -A urls | |
| declare -A shas | |
| for target in "x86_64-unknown-linux-gnu" "x86_64-apple-darwin" "aarch64-apple-darwin"; do | |
| asset_name="semver.${target}.tar.gz" | |
| url="https://github.com/Optum/semver-cli/releases/download/${VERSION}/${asset_name}" | |
| echo "Downloading ${asset_name} using GitHub CLI" | |
| gh release download "${VERSION}" --pattern "${asset_name}" --dir assets --repo Optum/semver-cli | |
| sha=$(sha256sum "assets/${asset_name}" | cut -d " " -f1) | |
| urls[$target]=$url | |
| shas[$target]=$sha | |
| echo "Target: $target, URL: $url, SHA: $sha" | |
| done | |
| # Generate the Homebrew formula | |
| cat > Formula/semver.rb << EOF | |
| # typed: false | |
| # frozen_string_literal: true | |
| # This file was generated by GoReleaser. DO NOT EDIT. | |
| class Semver < Formula | |
| desc "A cli for common semantic versioning operations" | |
| homepage "https://github.com/Optum/semver-cli" | |
| version "${VERSION}" | |
| license "Apache2" | |
| on_macos do | |
| if Hardware::CPU.intel? | |
| url "${urls[x86_64-apple-darwin]}" | |
| sha256 "${shas[x86_64-apple-darwin]}" | |
| def install | |
| bin.install "semver" | |
| end | |
| end | |
| if Hardware::CPU.arm? | |
| url "${urls[aarch64-apple-darwin]}" | |
| sha256 "${shas[aarch64-apple-darwin]}" | |
| def install | |
| bin.install "semver" | |
| end | |
| end | |
| end | |
| on_linux do | |
| if Hardware::CPU.intel? | |
| url "${urls[x86_64-unknown-linux-gnu]}" | |
| sha256 "${shas[x86_64-unknown-linux-gnu]}" | |
| def install | |
| bin.install "semver" | |
| end | |
| end | |
| if Hardware::CPU.arm? && Hardware::CPU.is_64_bit? | |
| raise "Not yet supported" | |
| end | |
| end | |
| test do | |
| system "#{bin}/semver --version" | |
| end | |
| end | |
| EOF | |
| echo "Generated Formula/semver.rb:" | |
| cat Formula/semver.rb | |
| # Output to GitHub Summary | |
| cat >> $GITHUB_STEP_SUMMARY << EOF | |
| ## Homebrew Formula Generated | |
| Successfully generated Homebrew formula for version **${VERSION}**. | |
| ### Formula Details | |
| - **Version**: ${VERSION} | |
| - **Platforms**: Linux x86_64, macOS x86_64, macOS ARM64 | |
| - **License**: Apache2 | |
| ### File Generated | |
| \`\`\`ruby | |
| $(cat Formula/semver.rb) | |
| \`\`\` | |
| EOF | |
| # touch 1 | |
| - name: Create PR to Homebrew Tap | |
| if: ${{ github.event_name == 'release' && github.event.release.prerelease == false }} | |
| env: | |
| VERSION: ${{ needs.version.outputs.version }} | |
| run: | | |
| # Clone the homebrew-tap repository | |
| gh repo clone Optum/homebrew-tap homebrew-tap-repo | |
| cd homebrew-tap-repo | |
| # Create a new branch | |
| branch_name="update-semver-${VERSION}" | |
| git checkout -b "${branch_name}" | |
| # Copy the generated formula | |
| cp ../Formula/semver.rb Formula/semver.rb | |
| # Commit and push the changes | |
| git add Formula/semver.rb | |
| git commit -m "Update semver formula to version ${VERSION}" | |
| git push origin "${branch_name}" | |
| # Create the PR | |
| gh pr create \ | |
| --title "Update semver formula to version ${VERSION}" \ | |
| --body "This PR updates the semver formula to version ${VERSION}. | |
| This PR was automatically generated by the semver-cli release workflow. | |
| Changes: | |
| - Updated version to ${VERSION} | |
| - Updated download URLs and SHA256 hashes for all supported platforms" \ | |
| --head "${branch_name}" \ | |
| --base main | |
| tags: | |
| if: ${{ github.event.release.prerelease == false }} | |
| runs-on: ubuntu-latest | |
| needs: | |
| - version | |
| - assets | |
| - docker | |
| - homebrew | |
| permissions: | |
| contents: write | |
| id-token: write | |
| env: | |
| GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | |
| steps: | |
| - name: Configure Git | |
| run: | | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
| gh auth setup-git | |
| - uses: actions/checkout@v4 | |
| - name: Create Tags | |
| run: | | |
| git tag "v${{ needs.version.outputs.version }}" | |
| git push origin --tags | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |