Skip to content

Feat/rust cicd

Feat/rust cicd #3

Workflow file for this run

name: GBFS Rust Language Bindings - PR Check
on:
pull_request:
branches:
- master
paths:
- "models/rust/**"
jobs:
tests:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./models/rust
steps:
- uses: actions/checkout@v4
- run: cargo build --release
- run: cargo test --release
- run: cargo clippy
check-versions:
name: check-version-job
runs-on: ubuntu-latest
outputs:
has-version-changed: ${{ steps.version-change-check.outputs.VERSION_CHANGED }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Extract Version from Current Branch
id: extract_version_current
working-directory: models/rust
run: echo "VERSION_CURRENT=$(grep '^version =' Cargo.toml | head -n 1 | awk -F'"' '{print $2}')" >> $GITHUB_OUTPUT
- name: Checkout master branch
run: |
git fetch origin master
git checkout master
- name: Extract Version from Master Branch
id: extract_version_master
working-directory: models/rust
run: echo "VERSION_MASTER=$(grep '^version =' Cargo.toml | head -n 1 | awk -F'"' '{print $2}')" >> $GITHUB_OUTPUT
- name: Compare versions
id: version-change-check
env:
local_version: ${{ steps.extract_version_current.outputs.VERSION_CURRENT }}
master_version: ${{ steps.extract_version_master.outputs.VERSION_MASTER }}
run: |
if [ "$local_version" != "$master_version" ]; then
echo "Local branch version ($local_version) is different from master branch version ($master_version)"
echo "VERSION_CHANGED=true" >> $GITHUB_OUTPUT
else
echo "Local branch version ($local_version) is the same as master branch version ($master_version)"
echo "Please update the models/rust/Cargo.toml version so that your changes will be published."
echo "VERSION_CHANGED=false" >> $GITHUB_OUTPUT
fi
github-pr-comment:
name: pr comment to update pom.xml
needs: [check-versions]
if: needs.check-versions.outputs.has-version-changed == 'false'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Comment on PR to update pom.xml
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Thank you for opening/editing this pull request. Please update the models/rust/Cargo.toml version so that your changes will be published.'
});
- name: Fail the workflow
run: exit 1