diff --git a/.github/workflows/build_prod.yml b/.github/workflows/build_prod.yml new file mode 100644 index 0000000..3a80584 --- /dev/null +++ b/.github/workflows/build_prod.yml @@ -0,0 +1,126 @@ +name: Package vngcloud-csi-volume-modifier into container image on MAIN branch + +on: + push: + tags: + - 'v*' + pull_request: + tags: + - 'v*' + +jobs: + package-image: + runs-on: ubuntu-latest + environment: + name: prod # Set the environment name + if: contains(github.event.head_commit.message, '[build]') + steps: + - name: Send alert that a new commit has been created + uses: appleboy/telegram-action@master + with: + to: ${{ secrets.TELEGRAM_TO }} + token: ${{ secrets.TELEGRAM_TOKEN }} + format: markdown + message: | + 🚀 *[PROD] NEW COMMIT* + *Repository*: `${{ github.repository }}` + *Author*: `${{ github.actor }}` + *Action*: Building `vngcloud-csi-volume-modifier` image + *Commit message*: + ``` + ${{ github.event.commits[0].message }} + ``` + *See changes*: https://github.com/${{ github.repository }}/commit/${{github.sha}} + *See workflow*: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + - uses: actions/checkout@v4 + - name: Login to VngCloud Registry + uses: docker/login-action@v3 + with: + registry: ${{ secrets.VCR_REGISTRY }} + username: ${{ secrets.VCR_USERNAME }} + password: ${{ secrets.VCR_PASSWORD }} + - name: Build vngcloud-csi-volume-modifier image + continue-on-error: true + run: | + export REGISTRY=${{ secrets.VCR_REGISTRY }} + export VERSION=${{ github.ref_name }} + make docker-build + echo "VERSION=${VERSION}" >> $GITHUB_ENV + - name: Send alert that the image has been built failed + uses: appleboy/telegram-action@master + if: ${{ failure() }} + with: + to: ${{ secrets.TELEGRAM_TO }} + token: ${{ secrets.TELEGRAM_TOKEN }} + format: markdown + message: | + ⛔ *[PROD] ERROR* + *Repository*: `${{ github.repository }}` + *Author*: `${{ github.actor }}` + *Action*: Failed to build `vngcloud-csi-volume-modifier` image + *Commit message*: + ``` + ${{ github.event.commits[0].message }} + ``` + *See changes*: https://github.com/${{ github.repository }}/commit/${{github.sha}} + *See workflow*: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + - name: Send alert that the image has been built success + uses: appleboy/telegram-action@master + if: ${{ success() }} + with: + to: ${{ secrets.TELEGRAM_TO }} + token: ${{ secrets.TELEGRAM_TOKEN }} + format: markdown + message: | + 📦 *[PROD] SUCCESS* + *Repository*: `${{ github.repository }}` + *Author*: `${{ github.actor }}` + *Action*: The `vngcloud-csi-volume-modifier:${{ env.VERSION }}` image is built successfully, try to push it to VngCloud Registry + *Commit message*: + ``` + ${{ github.event.commits[0].message }} + ``` + *See changes*: https://github.com/${{ github.repository }}/commit/${{github.sha}} + *See workflow*: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + - name: Push vngcloud-csi-volume-modifier image + continue-on-error: true + run: | + export REGISTRY=${{ secrets.VCR_REGISTRY }} + export VERSION=$VERSION + make docker-push + - name: Send alert that the image has been pushed failed + uses: appleboy/telegram-action@master + if: ${{ failure() }} + with: + to: ${{ secrets.TELEGRAM_TO }} + token: ${{ secrets.TELEGRAM_TOKEN }} + format: markdown + message: | + ⛔ *[PROD] ERROR* + *Repository*: `${{ github.repository }}` + *Author*: `${{ github.actor }}` + *Action*: Failed to PUSH `vngcloud-csi-volume-modifier` image to VngCloud registry + *Commit message*: + ``` + ${{ github.event.commits[0].message }} + ``` + *See changes*: https://github.com/${{ github.repository }}/commit/${{github.sha}} + *See workflow*: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + - name: Send alert that the image has been pushed success + uses: appleboy/telegram-action@master + if: ${{ success() }} + with: + to: ${{ secrets.TELEGRAM_TO }} + token: ${{ secrets.TELEGRAM_TOKEN }} + format: markdown + message: | + 🛸 *[PROD] SUCCESS* + *Repository*: `${{ github.repository }}` + *Author*: `${{ github.actor }}` + *Action*: The `vngcloud-csi-volume-modifier:${{ env.VERSION }}` image is pushed successfully to VngCloud registry + *Commit message*: + ``` + ${{ github.event.commits[0].message }} + ``` + *See changes*: https://github.com/${{ github.repository }}/commit/${{github.sha}} + *See workflow*: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..429a56c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,90 @@ +name: Release vngcloud-csi-volume-modifier project + +on: + push: + tags: + - 'v*' + pull_request: + tags: + - 'v*' + +jobs: + build: + name: GoReleaser build + runs-on: ubuntu-latest + + steps: + - name: Send alert that a new release has been created + uses: appleboy/telegram-action@master + with: + to: ${{ secrets.TELEGRAM_TO }} + token: ${{ secrets.TELEGRAM_TOKEN }} + format: markdown + message: | + 🚀 *[RELEASE] NEW RELEASE* + *Repository*: `${{ github.repository }}` + *Author*: `${{ github.actor }}` + *Action*: Building `vngcloud-csi-volume-modifier:${{ github.ref_name }}` application + *Commit message*: + ```text + ${{ github.event.commits[0].message }} + ``` + *See changes*: https://github.com/${{ github.repository }}/commit/${{github.sha}} + *See workflow*: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + with: + fetch-depth: 0 # See: https://goreleaser.com/ci/actions/ + + - name: Set up Go 1.22 + uses: actions/setup-go@v4 + continue-on-error: true + with: + go-version: 1.22 + id: go + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + continue-on-error: true + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GO_RELEASER_GITHUB_TOKEN }} + - name: Send alert that the image has been built failed + uses: appleboy/telegram-action@master + if: ${{ failure() }} + with: + to: ${{ secrets.TELEGRAM_TO }} + token: ${{ secrets.TELEGRAM_TOKEN }} + format: markdown + message: | + ⛔ *[RELEASE] ERROR* + *Repository*: `${{ github.repository }}` + *Author*: `${{ github.actor }}` + *Action*: Failed to release `vngcloud-csi-volume-modifier:${{ github.ref_name }}` application + *Commit message*: + ```text + ${{ github.event.commits[0].message }} + ``` + *See changes*: https://github.com/${{ github.repository }}/commit/${{github.sha}} + *See workflow*: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + - name: Send alert that the image has been built success + uses: appleboy/telegram-action@master + if: ${{ success() }} + with: + to: ${{ secrets.TELEGRAM_TO }} + token: ${{ secrets.TELEGRAM_TOKEN }} + format: markdown + message: | + 📦 *[RELEASE] SUCCESS* + *Repository*: `${{ github.repository }}` + *Author*: `${{ github.actor }}` + *Action*: The `vngcloud-csi-volume-modifier:${{ github.ref_name }}` application is built successfully + *Commit message*: + ```text + ${{ github.event.commits[0].message }} + ``` + *See changes*: https://github.com/${{ github.repository }}/commit/${{github.sha}} + *See workflow*: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} \ No newline at end of file diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..1ebf0cc --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,3 @@ +# .goreleaser.yaml +builds: + - skip: true \ No newline at end of file