ci #67
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: 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 }} | |
# Specify pat token here uses that identity to push changes and skip | |
# branch protections | |
- uses: actions/checkout@v4 | |
with: | |
path: repo | |
token: ${{ secrets.GO_COMMON_API_GEN_TOKEN}} | |
- name: Update the sources | |
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 user.name 'CI Workflow' | |
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 | |
run: | | |
gh release create $TAG \ | |
--latest \ | |
--generate-notes \ | |
--title "feat: updated to go-datatrails-common-api@$TAG" |