orign 0.2.3

A globally distributed container orchestrator
Documentation
# .github/workflows/release.yml

name: Tag Version and Build Release

on:
  push:
    branches:
      - main

permissions:
  contents: write

jobs:
  create_tag:
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.get_version.outputs.version }}
      version_changed: ${{ steps.check_version.outputs.version_changed }}
    steps:
      - name: Checkout Code
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Get Previous Version
        id: get_prev_version
        run: |
          git fetch --tags
          PREV_VERSION=$(git tag --sort=-v:refname | head -n 1 | sed 's/^v//')
          echo "prev_version=${PREV_VERSION}" >> $GITHUB_OUTPUT

      - name: Get Current Version
        id: get_version
        run: |
          VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[] | select(.name=="orign") | .version')
          echo "version=${VERSION}" >> $GITHUB_OUTPUT

      - name: Check if Version Changed
        id: check_version
        run: |
          if [ "${{ steps.get_prev_version.outputs.prev_version }}" != "${{ steps.get_version.outputs.version }}" ]; then
            echo "version_changed=true" >> $GITHUB_OUTPUT
          else
            echo "version_changed=false" >> $GITHUB_OUTPUT
          fi

      - name: Create Tag
        if: ${{ steps.check_version.outputs.version_changed == 'true' }}
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git tag -a "v${{ steps.get_version.outputs.version }}" -m "Release version ${{ steps.get_version.outputs.version }}"
          git push origin "v${{ steps.get_version.outputs.version }}"

  build_and_release:
    needs: create_tag
    if: ${{ needs.create_tag.outputs.version_changed == 'true' }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        include:
          - os: macos-14
            target: aarch64-apple-darwin
            arch: arm64
            platform: darwin
          - os: ubuntu-22.04
            target: x86_64-unknown-linux-gnu
            arch: amd64
            platform: linux

    steps:
      - name: Checkout Code
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      # Build steps
      - name: Install Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          target: ${{ matrix.target }}
          override: true

      - name: Install Dependencies
        run: |
          if [ "${{ matrix.platform }}" == "darwin" ]; then
            brew install openssl pkg-config
            echo "PKG_CONFIG_PATH=$(brew --prefix openssl)/lib/pkgconfig" >> $GITHUB_ENV
          else
            sudo apt-get update && sudo apt-get install -y \
              musl-tools \
              pkg-config \
              libssl-dev
          fi
        shell: bash

      - name: Build Binary
        env:
          TAG_NAME: "v${{ needs.create_tag.outputs.version }}"
        run: |
          echo "Building version $TAG_NAME..."
          cargo build --release --target ${{ matrix.target }}

      - name: Create Archive
        env:
          TAG_NAME: "v${{ needs.create_tag.outputs.version }}"
        run: |
          BINARY_NAME=orign
          TARGET_DIR="target/${{ matrix.target }}/release"
          TAR_NAME="${BINARY_NAME}-${TAG_NAME}-${{ matrix.platform }}-${{ matrix.arch }}.tar.gz"

          echo "Creating archive ${TAR_NAME}..."
          tar -czvf "${TAR_NAME}" -C "${TARGET_DIR}" "${BINARY_NAME}"

          echo "Generating checksum..."
          if [[ "${{ matrix.platform }}" == "darwin" ]]; then
            shasum -a 256 "${TAR_NAME}" >> checksums.txt
          else
            sha256sum "${TAR_NAME}" >> checksums.txt
          fi

      - name: Upload Artifact
        uses: actions/upload-artifact@v4
        with:
          name: binaries-${{ matrix.platform }}-${{ matrix.arch }}
          path: |
            *.tar.gz
            checksums.txt
          retention-days: 1

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v1
        with:
          tag_name: "v${{ needs.create_tag.outputs.version }}"
          files: "*.tar.gz"
          body: "Release version ${{ needs.create_tag.outputs.version }}"

      - id: 'auth'
        uses: 'google-github-actions/auth@v2'
        with:
          credentials_json: '${{ secrets.GCS_SA_JSON }}'

      - name: 'Set up Cloud SDK'
        uses: 'google-github-actions/setup-gcloud@v2'

      - name: 'Use gcloud CLI'
        run: 'gcloud info'

      - name: 'Use gcloud CLI'
        run: 'gcloud auth list --filter=status:ACTIVE --format="value(account)"'

      - name: Verify Authentication
        run: |
          gsutil ls
        shell: bash

      - name: Upload to GCS
        run: |
          # Upload versioned files to version-specific directory
          gsutil cp *.tar.gz gs://orign/releases/v${{ needs.create_tag.outputs.version }}/
          gsutil cp checksums.txt gs://orign/releases/v${{ needs.create_tag.outputs.version }}/
          
          # Create and upload "latest" named files
          for file in *.tar.gz; do
            latest_file=$(echo $file | sed "s/v${{ needs.create_tag.outputs.version }}/latest/")
            cp "$file" "$latest_file"
          done
          
          # Generate new checksums for latest files
          rm checksums.txt
          if [[ "${{ matrix.platform }}" == "darwin" ]]; then
            shasum -a 256 *latest*.tar.gz >> checksums.txt
          else
            sha256sum *latest*.tar.gz >> checksums.txt
          fi
          
          # Upload latest files
          gsutil cp *latest*.tar.gz gs://orign/releases/latest/
          gsutil cp checksums.txt gs://orign/releases/latest/
        shell: bash