diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..dd06008 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,86 @@ +--- +name: Semantic Release + +on: + push: + branches: + - main + +jobs: + semantic-release: + name: Release + runs-on: ubuntu-latest + permissions: + contents: write # to be able to publish a GitHub release + issues: write # to be able to comment on released issues + pull-requests: write # to be able to comment on released pull requests + outputs: + next-version: ${{ steps.semantic-release.outputs.next-version }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "lts/*" + + - name: Install Semantic Release + run: > + npm install + semantic-release + conventional-changelog-conventionalcommits + @semantic-release/changelog + @semantic-release/exec + @semantic-release/git + semantic-release-major-tag + + - name: Verify the integrity of provenance attestations and registry signatures for installed dependencies + run: npm audit signatures + + - name: Run Semantic Release + id: semantic-release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + npx semantic-release + VERSION=$(cat VERSION) + echo "Next version: $VERSION" + echo "next-version=$VERSION" >> $GITHUB_OUTPUT + + docker: + runs-on: ubuntu-latest + needs: semantic-release + if: ${{ needs.semantic-release.outputs.next-version }} + permissions: + packages: write # required to push to GHCR + contents: read + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build Docker image + run: | + IMAGE_NAME="ghcr.io/${{ github.repository_owner }}/cpp-cli" + V_TAG="${IMAGE_NAME}:v${{ needs.semantic-release.outputs.next-version }}" + LATEST_TAG="${IMAGE_NAME}:latest" + + echo "Building image $V_TAG and $LATEST_TAG" + docker build -t "$V_TAG" -t "$LATEST_TAG" . + + - name: Push Docker image + run: | + IMAGE_NAME="ghcr.io/${{ github.repository_owner }}/cpp-cli" + docker push "${IMAGE_NAME}:v${{ needs.semantic-release.outputs.next-version }}" + docker push "${IMAGE_NAME}:latest" diff --git a/.github/workflows/semantic-release.yaml b/.github/workflows/semantic-release.yaml deleted file mode 100644 index 7367597..0000000 --- a/.github/workflows/semantic-release.yaml +++ /dev/null @@ -1,45 +0,0 @@ ---- -name: Semantic Release - -on: - push: - branches: - - main - -jobs: - release: - name: Release - runs-on: ubuntu-latest - permissions: - contents: write # to be able to publish a GitHub release - issues: write # to be able to comment on released issues - pull-requests: write # to be able to comment on released pull requests - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: "lts/*" - - - name: Install Semantic Release - run: > - npm install - semantic-release - conventional-changelog-conventionalcommits - @semantic-release/changelog - @semantic-release/exec - @semantic-release/git - semantic-release-major-tag - - - name: Verify the integrity of provenance attestations and registry signatures for installed dependencies - run: npm audit signatures - - - name: Run Semantic Release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: npx semantic-release diff --git a/.releaserc.yaml b/.releaserc.yaml index 92b4503..10ec844 100644 --- a/.releaserc.yaml +++ b/.releaserc.yaml @@ -13,3 +13,5 @@ plugins: - assets: - CHANGELOG.md - semantic-release-major-tag + - - "@semantic-release/exec" + - prepareCmd: "echo ${nextRelease.version} > VERSION" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5cc017c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM ubuntu:22.04 AS builder + +RUN apt update && apt install -y build-essential cmake + +WORKDIR /app + +COPY CMakeLists.txt ./ +COPY src ./src +COPY tests ./tests + +RUN mkdir build && cd build && \ + cmake .. && \ + make + +FROM ubuntu:22.04 + +WORKDIR /app + +COPY --from=builder /app/build/cpp-cli /usr/local/bin/cpp-cli + +ENTRYPOINT ["cpp-cli"] diff --git a/README.md b/README.md index fc20a04..a274f23 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ Hello world C++ CLI application. ## Features -- [CI](.github/workflows/ci.yaml) -- [Semantic Release](.github/workflows/semantic-release.yaml) on merge to the `main` branch +- [CI](.github/workflows/ci.yaml) on PR or merge to the `main` branch +- [Release](.github/workflows/release.yaml) on merge to the `main` branch ## Development and Testing @@ -44,3 +44,11 @@ Cleanup: popd rm -rf build/ ``` + +## Distribution + +Docker build and run: + +```shell +sudo docker run --rm $(sudo docker build -q .) +```