diff --git a/.github/workflows/build-ci.yaml b/.github/workflows/build-ci.yaml index dcc865a..aa44ecf 100644 --- a/.github/workflows/build-ci.yaml +++ b/.github/workflows/build-ci.yaml @@ -1,24 +1,26 @@ -name: LumenLab CI/CD +name: Build on: pull_request: - + types: [opened, synchronize, reopened] push: - branches-ignore: + branches: - main - tags-ignore: - - 'v*' - workflow_dispatch: {} +permissions: + contents: write jobs: - build_and_test: + pr_build_and_test: + if: github.event_name == 'pull_request' runs-on: ubuntu-latest steps: - - name: Checkout repository + - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 - - name: Cache PlatformIO & pip + - name: Cache pip and PlatformIO uses: actions/cache@v4 with: path: | @@ -34,46 +36,98 @@ jobs: - name: Inject credentials run: python3 ${{ github.workspace }}/tools/setup_dev_env.py - - name: Install PlatformIO + - name: Install platformio core libraries run: pip install --upgrade platformio - - name: Build LumenLab firmware - run: pio run --environment release + - name: Build LumenLab + run: pio run - - name: Run native tests + - name: Run tests run: pio test --environment native - docker_build_push: - if: github.ref == 'refs/heads/main' - needs: build_and_test + release_on_main: + if: github.event_name == 'push' && github.ref == 'refs/heads/main' runs-on: ubuntu-latest + needs: [] steps: - - name: Checkout repository + - name: Checkout (full) uses: actions/checkout@v4 + with: + fetch-depth: 0 - - name: Log in to Docker Hub - uses: docker/login-action@v2 + - name: Cache pip and PlatformIO + uses: actions/cache@v4 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + path: | + ~/.cache/pip + ~/.platformio/.cache + key: ${{ runner.os }}-pio - - name: Determine Docker tags - id: docker_tags - run: | - IMAGE=mcdanieles/lumenlab - echo "LATEST_TAG=latest" >> $GITHUB_ENV - VERSION_TAG=$(git describe --tags --exact-match 2>/dev/null || echo "") - echo "VERSION_TAG=$VERSION_TAG" >> $GITHUB_ENV - echo "IMAGE=$IMAGE" >> $GITHUB_ENV - echo "Tags: latest=${LATEST_TAG}, version=${VERSION_TAG}" - - - name: Build Docker image - run: | - docker build -t $IMAGE:$LATEST_TAG${VERSION_TAG:+ -t $IMAGE:$VERSION_TAG} . + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Inject credentials + run: python3 ${{ github.workspace }}/tools/setup_dev_env.py + + - name: Install platformio core libraries + run: pip install --upgrade platformio - - name: Push Docker image + - name: Build release + run: pio run -e release + + - name: Run tests + run: pio test --environment native + + - name: Create and push tag for release + id: tag_release run: | - docker push $IMAGE:$LATEST_TAG - if [[ -n "$VERSION_TAG" ]]; then - docker push $IMAGE:$VERSION_TAG + git fetch --tags + latest_tag=$(git tag --list --sort=-v:refname | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+$' | head -n1 || true) + if [ -z "$latest_tag" ]; then + new_tag=v0.0.1 + else + t=${latest_tag#v} + IFS='.' read -r major minor patch <<< "$t" + patch=$((patch+1)) + new_tag="v${major}.${minor}.${patch}" fi + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git tag -a "$new_tag" -m "Release $new_tag" + git push origin "$new_tag" + echo "tag=$new_tag" >> $GITHUB_OUTPUT + + - name: Create GitHub Release + id: create_release + uses: actions/create-release@v1 + with: + tag_name: ${{ steps.tag_release.outputs.tag }} + release_name: Release ${{ steps.tag_release.outputs.tag }} + draft: false + prerelease: false + + - name: Upload firmware.bin + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: .pio/build/release/firmware.bin + asset_name: firmware.bin + asset_content_type: application/octet-stream + + - name: Upload bootloader.bin + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: .pio/build/release/bootloader.bin + asset_name: bootloader.bin + asset_content_type: application/octet-stream + + - name: Upload partitions.bin + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: .pio/build/release/partitions.bin + asset_name: partitions.bin + asset_content_type: application/octet-stream \ No newline at end of file