|
| 1 | +name: Release Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | +jobs: |
| 8 | + build-and-push-image: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + permissions: |
| 11 | + contents: read |
| 12 | + packages: write |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout repository |
| 16 | + uses: actions/checkout@v3 |
| 17 | + |
| 18 | + - name: Log in to GitHub Container Registry |
| 19 | + uses: docker/login-action@v2 |
| 20 | + with: |
| 21 | + registry: ghcr.io |
| 22 | + username: ${{ github.actor }} |
| 23 | + password: ${{ secrets.PKGTOKEN }} |
| 24 | + |
| 25 | + - name: Set up VERSION environment variable |
| 26 | + run: echo "VERSION=${GITHUB_REF_NAME}" >> $GITHUB_ENV |
| 27 | + |
| 28 | + - name: Set up IMAGE_NAME environment variable |
| 29 | + run: | |
| 30 | + ORG_REPO="${{ github.repository }}" |
| 31 | + ORG=$(echo "${ORG_REPO}" | cut -d '/' -f 1 | tr '[:upper:]' '[:lower:]') |
| 32 | + REPO=$(echo "${ORG_REPO}" | cut -d '/' -f 2 | tr '[:upper:]' '[:lower:]') |
| 33 | + IMAGE_NAME="ghcr.io/${ORG}/${REPO}/${REPO}-app" |
| 34 | + echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV |
| 35 | +
|
| 36 | + - name: Pull latest image |
| 37 | + run: docker pull ${{ env.IMAGE_NAME }}:latest |
| 38 | + |
| 39 | + - name: Tag image with release version |
| 40 | + run: docker tag ${{ env.IMAGE_NAME }}:latest ${{ env.IMAGE_NAME }}:${{ env.VERSION }} |
| 41 | + |
| 42 | + - name: Push image to GitHub Container Registry |
| 43 | + run: docker push ${{ env.IMAGE_NAME }}:${{ env.VERSION }} |
| 44 | + release: |
| 45 | + runs-on: ubuntu-latest |
| 46 | + |
| 47 | + steps: |
| 48 | + - name: Checkout code |
| 49 | + uses: actions/checkout@v4 |
| 50 | + with: |
| 51 | + submodules: true |
| 52 | + |
| 53 | + - name: Set up Go |
| 54 | + uses: actions/setup-go@v4 |
| 55 | + with: |
| 56 | + go-version: "1.24.2" |
| 57 | + |
| 58 | + - name: Enable Go Modules and Download Dependencies |
| 59 | + run: | |
| 60 | + go mod tidy |
| 61 | + go mod download |
| 62 | +
|
| 63 | + - name: Install protoc |
| 64 | + run: | |
| 65 | + sudo apt-get update |
| 66 | + sudo apt-get install -y protobuf-compiler |
| 67 | + go install google.golang.org/protobuf/cmd/protoc-gen-go@latest |
| 68 | + go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest |
| 69 | + echo "$GOPATH/bin" >> $GITHUB_PATH |
| 70 | +
|
| 71 | + - name: Install Docker |
| 72 | + run: | |
| 73 | + sudo apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release |
| 74 | + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg |
| 75 | + echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null |
| 76 | + sudo apt-get update |
| 77 | + sudo apt-get install -y docker-ce docker-ce-cli containerd.io |
| 78 | +
|
| 79 | + - name: Install Docker Compose |
| 80 | + run: | |
| 81 | + sudo wget "https://github.com/docker/compose/releases/download/v2.33.1/docker-compose-linux-x86_64" -O /usr/bin/docker-compose |
| 82 | + sudo chmod +x /usr/bin/docker-compose |
| 83 | +
|
| 84 | + - name: Build and Release |
| 85 | + run: make release |
| 86 | + |
| 87 | + - name: Upload artifacts 1 |
| 88 | + uses: actions/upload-artifact@v4 |
| 89 | + with: |
| 90 | + name: StealthIMGroupUser |
| 91 | + path: ./bin/StealthIMGroupUser |
| 92 | + |
| 93 | + - name: Upload artifacts 2 |
| 94 | + uses: actions/upload-artifact@v4 |
| 95 | + with: |
| 96 | + name: StealthIMGroupUser.exe |
| 97 | + path: ./bin/StealthIMGroupUser.exe |
| 98 | + |
| 99 | + - name: Upload artifacts 3 |
| 100 | + uses: actions/upload-artifact@v4 |
| 101 | + with: |
| 102 | + name: StealthIMGroupUser.docker.zst |
| 103 | + path: ./bin/StealthIMGroupUser.docker.zst |
| 104 | + set-release: |
| 105 | + runs-on: ubuntu-latest |
| 106 | + needs: release |
| 107 | + permissions: |
| 108 | + packages: write |
| 109 | + contents: write |
| 110 | + |
| 111 | + steps: |
| 112 | + - name: Download File Linux |
| 113 | + uses: actions/download-artifact@v4 |
| 114 | + with: |
| 115 | + name: StealthIMGroupUser |
| 116 | + |
| 117 | + - name: Download File Windows |
| 118 | + uses: actions/download-artifact@v4 |
| 119 | + with: |
| 120 | + name: StealthIMGroupUser.exe |
| 121 | + |
| 122 | + - name: Download File Docker |
| 123 | + uses: actions/download-artifact@v4 |
| 124 | + with: |
| 125 | + name: StealthIMGroupUser.docker.zst |
| 126 | + |
| 127 | + - name: Update Release |
| 128 | + uses: softprops/action-gh-release@v2 |
| 129 | + with: |
| 130 | + files: | |
| 131 | + StealthIMGroupUser |
| 132 | + StealthIMGroupUser.exe |
| 133 | + StealthIMGroupUser.docker.zst |
0 commit comments