Skip to content

check in api spec with client #12

check in api spec with client

check in api spec with client #12

Workflow file for this run

name: Update candlepin binding if new release
on:
push:
jobs:
CheckLatestVersionAndRun:
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- name: Checkout
with:
fetch-depth: 0 # Needed for github-action-get-previous-tag
uses: actions/checkout@v3
- name: Get current build version
id: repoRelease
uses: "WyriHaximus/github-action-get-previous-tag@v1"
with:
prefix: release/
fallback: 1.0.0 # Optional fallback tag to use when no tag can be found
- name: Set up yq
uses: frenck/action-setup-yq@v1
- name: Get current version from file
id: getRelease
run: |
curl https://raw.githubusercontent.com/candlepin/candlepin/main/api/candlepin-api-spec.yaml -o candlepin-api-spec.yaml
yq -r '.info.version' < candlepin-api-spec.yaml
version="`yq -r '.info.version' < candlepin-api-spec.yaml`"
major="v`echo $version | awk -F '.' '{print $1}'`"
tag="release/v$version"
echo $version
echo $major
echo $tag
echo "version=$version" >> $GITHUB_OUTPUT
echo "tag=$tag" >> $GITHUB_OUTPUT
echo "major=$major" >> $GITHUB_OUTPUT
# If check passes, latest build is up to date and the action stops
- name: Update version
if: steps.getRelease.outputs.tag != steps.repoRelease.outputs.tag
run: |
echo "New candlepin version available >> ${{ steps.getRelease.outputs.tag }}! (Current build version ${{ steps.repoRelease.outputs.tag }})"
- name: Remove old files
if: steps.getRelease.outputs.tag != steps.repoRelease.outputs.tag
run: |
rm -rf release/
- name: Build binding
if: steps.getRelease.outputs.tag != steps.repoRelease.outputs.tag
run: |
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:latest-release generate \
-i /local/candlepin-api-spec.yaml \
-g go \
--git-user-id=content-services \
--git-repo-id=caliri/release/${{ steps.getRelease.outputs.major }} \
--package-name=caliri \
-o /local/release \
-p packageVersion=${{ steps.getRelease.outputs.version }}
- uses: actions/setup-go@v2
if: steps.getRelease.outputs.tag != steps.repoRelease.outputs.tag
with:
go-version: "1.18"
- name: Run Go Tests
if: steps.getRelease.outputs.tag != steps.repoRelease.outputs.tag
run: |
cd release
sudo chmod 777 go.mod go.sum
go get github.com/stretchr/testify/assert
go test ./...
- name: Commit new client
id: commit
if: steps.getRelease.outputs.tag != steps.repoRelease.outputs.tag
run: |
git config --global user.name ${{secrets.GIT_USER_NAME}}
git config --global user.email ${{secrets.GIT_USER_EMAIL}}
git add release/
git add candlepin-api-spec.yaml
git commit -am "Update bindings to ${{ steps.getRelease.outputs.tag }}"
git push
echo "NEW_SHA=`git rev-parse HEAD`" >> $GITHUB_OUTPUT
# This pushes an update and release after build <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- name: Tag and Release version
if: steps.getRelease.outputs.tag != steps.repoRelease.outputs.tag
uses: avakar/tag-and-release@v1
with:
commit: ${{steps.commit.outputs.NEW_SHA}}
tag_name: ${{ steps.getRelease.outputs.tag }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}