Skip to content

update build and release #7

update build and release

update build and release #7

Workflow file for this run

name: Build and Release
on:
push:
branches: [main]
tags:
- 'v*'
pull_request:
jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
include:
- os: ubuntu-latest
output_name: apkx
asset_name: apkx-linux-amd64
- os: windows-latest
output_name: apkx.exe
asset_name: apkx-windows-amd64
- os: macos-latest
output_name: apkx
asset_name: apkx-darwin-amd64
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Set up Java
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
- name: Build
run: |
go mod tidy
mkdir -p dist
go build -v -o dist/${{ matrix.output_name }} ./cmd/apkx/main.go
env:
CGO_ENABLED: 0
GOOS: ${{ runner.os == 'Windows' && 'windows' || runner.os == 'macOS' && 'darwin' || 'linux' }}
GOARCH: amd64
- name: Test
run: go test -v ./...
- name: Prepare Release Files
if: github.event_name == 'push'
run: |
# Create directories
mkdir -p release
mkdir -p release/config
# Copy binary
cp dist/${{ matrix.output_name }} release/
# Create minimal config if not exists
if [ ! -f "config/regexes.yaml" ]; then
echo "patterns:" > release/config/regexes.yaml
echo " - name: example" >> release/config/regexes.yaml
echo " regex: 'example'" >> release/config/regexes.yaml
else
cp -r config/* release/config/
fi
# Create minimal README if not exists
if [ ! -f "README.md" ]; then
echo "# apkX" > release/README.md
echo "APK analysis tool" >> release/README.md
else
cp README.md release/
fi
# Create minimal LICENSE if not exists
if [ ! -f "LICENSE" ]; then
echo "MIT License" > release/LICENSE
echo "Copyright (c) $(date +%Y)" >> release/LICENSE
else
cp LICENSE release/
fi
shell: bash
- name: Create Archive
if: github.event_name == 'push'
run: |
cd release
if [ "${{ runner.os }}" = "Windows" ]; then
7z a ../${{ matrix.asset_name }}.zip ./*
else
tar czf ../${{ matrix.asset_name }}.tar.gz ./*
fi
shell: bash
- name: Upload Build Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.asset_name }}
path: ${{ matrix.asset_name }}.*
retention-days: 7
release:
needs: build
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download Artifacts
uses: actions/download-artifact@v4
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: |
apkx-linux-amd64.tar.gz
apkx-windows-amd64.zip
apkx-darwin-amd64.tar.gz
draft: false
prerelease: false
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}