ci: fixed a bug in the commit message check (#53) #35
This file contains 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: PUSH CI | |
on: | |
push: | |
branches: | |
- main | |
env: | |
GO_VERSION: 1.21 | |
jobs: | |
commitlint_job: | |
name: Commit lint | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '22' | |
- name: Install commitlint | |
run: | | |
npm install --save-dev @commitlint/{cli,config-conventional} | |
- name: Validate current commit (last commit) with commitlint | |
run: npx commitlint --last --verbose | |
license_headers_job: | |
name: Add license headers | |
if: github.event.head_commit.committer.name != 'github-actions[bot]' | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Go environment | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
# Add all component folders for monorepos | |
cache-dependency-path: | | |
./registry/go.sum | |
./validator/go.sum | |
- name: Install NWA tool | |
run: go install github.com/B1NARY-GR0UP/nwa@latest | |
- name: Add missing license headers | |
run: nwa add -c "Syntio Ltd." -s **/*.xml ./registry ./validator | |
- name: Check and commit changes | |
id: check_commit | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
git add . | |
if ! git diff-index --quiet HEAD; then | |
git commit -m "style: add license headers" | |
echo "changes_committed=true" >> $GITHUB_ENV | |
else | |
echo "changes_committed=false" >> $GITHUB_ENV | |
echo "All necessary headers present." | |
fi | |
- name: Create a new branch for the PR | |
if: env.changes_committed == 'true' | |
run: | | |
git checkout -b "add-license-headers-${{ github.run_id }}" | |
git push origin HEAD | |
- name: Create pull request | |
if: env.changes_committed == 'true' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
gh pr create --base ${{ github.ref_name }} --head "add-license-headers-${{ github.run_id }}" --title "style: add license headers" --body "This PR adds license headers to the affected files. Recommendation: Merge this PR using the rebase-merge method" | |
upload_docker_images_job: | |
if: github.event.head_commit.committer.name == 'github-actions[bot]' || startsWith(github.event.head_commit.message, 'feat') || startsWith(github.event.head_commit.message, 'fix') | |
name: Build, push and sign Docker images | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write # required to generate JWT token | |
strategy: | |
matrix: | |
component: | |
- dockerfile-path: ./validator/docker/csv-validator/Dockerfile | |
image-name: schema-registry-csv-val | |
- dockerfile-path: ./validator/docker/validator/Dockerfile | |
image-name: schema-registry-validator | |
- dockerfile-path: ./validator/docker/xml-validator/Dockerfile | |
image-name: schema-registry-xml-val | |
- dockerfile-path: ./registry/docker/compatibility-checker/Dockerfile | |
image-name: schema-registry-compatibility | |
- dockerfile-path: ./registry/docker/initdb/Dockerfile | |
image-name: schema-registry-initdb | |
- dockerfile-path: ./registry/docker/registry/Dockerfile | |
image-name: schema-registry-api | |
- dockerfile-path: ./registry/docker/validity-checker/Dockerfile | |
image-name: schema-registry-validity | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Set image tag | |
run: | | |
if [ ${{ github.event.head_commit.committer.name }} == 'github-actions[bot]' ]; then | |
TAG=$(cat version.txt) | |
else | |
TAG=$(echo $GITHUB_SHA | cut -c 1-7) | |
fi | |
echo "TAG=$TAG" >> $GITHUB_ENV | |
- name: Docker Hub Login | |
run: | | |
echo "${{ secrets.DOCKERHUB_PASSWORD }}" | docker login --username "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin | |
- name: Build Docker image | |
run: | | |
docker build -t ${{ matrix.component.image-name }}:${{ env.TAG }} -f ${{ matrix.component.dockerfile-path }} . | |
- name: Check if Docker image tag exists | |
run: | | |
if docker manifest inspect syntioinc/dataphos-${{ matrix.component.image-name }}:${{ env.TAG }} > /dev/null 2>&1; then | |
echo "TAG_EXISTS=true" >> $GITHUB_ENV | |
else | |
echo "TAG_EXISTS=false" >> $GITHUB_ENV | |
fi | |
- name: Tag and Push Docker image | |
if: ${{ env.TAG_EXISTS == 'false' }} | |
run: | | |
docker tag ${{ matrix.component.image-name }}:${{ env.TAG }} syntioinc/dataphos-${{ matrix.component.image-name }}:${{ env.TAG }} | |
docker push syntioinc/dataphos-${{ matrix.component.image-name }}:${{ env.TAG }} | |
- name: Install cosign | |
if: ${{ github.event.head_commit.committer.name == 'github-actions[bot]' && env.TAG_EXISTS == 'false' }} | |
uses: sigstore/[email protected] | |
- name: Sign the Docker image | |
if: ${{ github.event.head_commit.committer.name == 'github-actions[bot]' && env.TAG_EXISTS == 'false' }} | |
run: | | |
digest=$(docker inspect --format='{{index .RepoDigests 0}}' syntioinc/dataphos-${{ matrix.component.image-name }}:${{ env.TAG }}) | |
cosign sign --yes "$digest" | |
- name: Image already exists | |
if: ${{ env.TAG_EXISTS == 'true' }} | |
run: echo "Docker image syntioinc/dataphos-${{ matrix.component.image-name }}:${{ env.TAG }} already exists. Skipping push." | |
release-please: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- uses: googleapis/release-please-action@v4 | |
with: | |
token: ${{ secrets.RELEASE_PLEASE_TOKEN }} | |
release-type: simple |