Skip to content

ci

ci #62

Workflow file for this run

name: ci
on:
workflow_dispatch:
inputs:
tag:
description: 'The tag to find in the upstream and replace here, the default is latest'
required: false
default: 'latest'
jobs:
update:
runs-on: ubuntu-latest
env:
ORG: datatrails
REPO: go-datatrails-common-api
ARTIFACT: go-datatrails-common-api.tar.gz
COMMIT_EMAIL: [email protected]
GH_TOKEN: ${{ github.token }}
steps:
- name: Resolve TAG
run: |
if [[ "$TAG" == "latest" ]]; then
echo "::info ::resolving tag ..."
TAG=$(curl -sL https://api.github.com/repos/${ORG}/${REPO}/releases/latest |
jq -r ".tag_name")
fi
echo "::info ::resolved tag: $TAG"
echo "TAG=$TAG" >> $GITHUB_ENV
env:
TAG: ${{ inputs.tag }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
path: repo
- name: Update the sources
env:
GH_TOKEN: ${{secrets.GO_COMMON_API_GEN_TOKEN}}
run: |
echo "TAG=$TAG"
# Note that it is not forced. only non hidden files and directories
# are removed.
# WARNING: top level files must be removed by hand if the are
# introduced by the archive and later removed.
# Current top level files are just:
# go.mod
# go.sum
for dd in $(ls -d repo/*/); do rm -r $dd; done
gh --repo $ORG/$REPO release download $TAG \
-p 'go-datatrails-common-api-gen.tar.gz'
tar -zxf go-datatrails-common-api-gen.tar.gz
pushd repo
cp -r ../go-datatrails-common-api-gen/* .
if [[ -z "$(git status --short)" ]]; then
echo "::warning :: no changes found"
# we keep the go-datatrails-common-api and
# go-datatrails-common-api-gen tags in sync so we sometimes have empty releases
exit 0
fi
# We don't, as a matter of policy, lint generated code. Any deep tests on
# the api generation should be done in go-datatrails-common-api. This is
# just a simple check for completely broken source
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.22.x'
- name: Unit tests
working-directory: repo
run: |
go build ./...
go test ./...
- name: Commit the updates
working-directory: repo
run: |
if [[ -z "$(git status --short)" ]]; then
echo "::warning :: no changes found"
# we keep the go-datatrails-common-api and
# go-datatrails-common-api-gen tags in sync so we sometimes have empty releases
exit 0
fi
git config --global url.'https://${{ secrets.GO_COMMON_API_GEN_TOKEN}}@github.com/datatrails'.insteadOf https://github.com/datatrails
go env -w GOPRIVATE="github.com/datatrails/*"
git config --global user.name 'landintrees'
git config --global user.email $COMMIT_EMAIL
git add .
git commit -am "feat: updated to go-datatrails-common-api@$TAG"
git push
- name: Release the updates
working-directory: repo
env:
GH_TOKEN: ${{secrets.GO_COMMON_API_GEN_TOKEN}}
run: |
gh auth status
gh release create $TAG \
--latest \
--generate-notes \
--title "feat: updated to go-datatrails-common-api@$TAG"