feat: docker release #20
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: Release Workflow | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
permissions: | |
contents: write | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: '1.23' | |
- name: Install GoReleaser | |
run: go install github.com/goreleaser/goreleaser@latest | |
- name: Check version | |
run: | | |
VERSION=$(cat VERSION.txt) | |
echo "version=$VERSION" >> $GITHUB_ENV | |
echo "Version: $VERSION" | |
- name: Run build using goreleaser on local | |
run: goreleaser release --snapshot --skip=publish --clean | |
- name: Create Tag | |
if: | | |
(github.event_name == 'push' && github.ref == 'refs/heads/main') || | |
(github.event_name == 'pull_request' && | |
github.event.action == 'closed' && | |
github.event.pull_request.merged == true && | |
github.event.pull_request.base.ref == 'main') | |
run: | | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "github-actions[bot]" | |
git tag "v${{ env.version }}" | |
git push origin "v${{ env.version }}" | |
- name: Run GoReleaser Release | |
if: | | |
(github.event_name == 'push' && github.ref == 'refs/heads/main') || | |
(github.event_name == 'pull_request' && | |
github.event.action == 'closed' && | |
github.event.pull_request.merged == true && | |
github.event.pull_request.base.ref == 'main') | |
run: | | |
export GORELEASER_CURRENT_TAG="v${{ env.version }}" | |
export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} | |
goreleaser release --clean --rm-dist | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Run GoReleaser Docker Push | |
if: | | |
(github.event_name == 'push' && github.ref == 'refs/heads/main') || | |
(github.event_name == 'pull_request' && | |
github.event.action == 'closed' && | |
github.event.pull_request.merged == true && | |
github.event.pull_request.base.ref == 'main') | |
run: | | |
export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} | |
goreleaser release --rm-dist --skip-publish --snapshot | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Download BPF object file | |
run: | | |
gh release download --repo SentinalFS/file-monitor --clobber --pattern "monitor.bpf.o" | |
env: | |
GH_TOKEN: ${{ github.token }} | |
- name: Decide to push or not | |
id: decide | |
run: | | |
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]]; then | |
echo "PUSH=true" >> $GITHUB_ENV | |
else | |
echo "PUSH=false" >> $GITHUB_ENV | |
fi | |
- name: Build Image | |
if: env.PUSH == 'false' | |
run: | | |
docker buildx build \ | |
--platform linux/amd64,linux/arm64 \ | |
--build-arg TARGETARCH=amd64 \ | |
--file Dockerfile \ | |
-t siddh34/go-ebpf-logger:latest \ | |
. | |
- name: Login to DockerHub | |
if: env.PUSH == 'true' | |
run: echo "${{ secrets.DOCKER_ACCESS_TOKEN }}" | docker login -u "siddh34" --password-stdin | |
- name: Build & Push Docker images | |
if: env.PUSH == 'true' | |
run: | | |
docker buildx build \ | |
--platform linux/amd64,linux/arm64 \ | |
--file Dockerfile \ | |
--push \ | |
-t siddh34/go-ebpf-logger:latest \ | |
. |