Skip to content

Merge pull request #119 from redhatci/maybe #73

Merge pull request #119 from redhatci/maybe

Merge pull request #119 from redhatci/maybe #73

Workflow file for this run

name: Ansible Galaxy Publish
on:
push:
branches:
- main
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Add epoch from commit date as patch version in galaxy.yml
run: |
set -x
z=$(TZ=UTC0 git show ${{ github.sha }} --no-patch --format=%cd --date=format-local:'%s')
ts=$(TZ=UTC0 git show ${{ github.sha }} --no-patch --format=%cd --date=format-local:'%Y%m%d%H%M')
sha=$(echo "${{ github.sha }}" | cut -c1-7)
cat >> galaxy.yml <<EOF
- "ts$ts"
- "git$sha"
EOF
tail -10 galaxy.yml
sed -i -r "s/^(version: .*)\.0$/\1.${z}/" galaxy.yml
grep ^version galaxy.yml
# Build and publish manually due to https://github.com/ansible/galaxy/issues/3287
# ansible/ansible-publish-action implements this
# https://github.com/ansible/creator-ee/blob/main/_build/devtools-publish
- name: Ansible Galaxy Collection Publish
run: >
rm -f ./*.tar.gz;
ansible-galaxy collection build -v --force "${SRC_PATH:-.}";
TARBALL=$(ls -1 ./*.tar.gz);
set +e;
publish=$(ansible-galaxy collection publish -v \
--server "${API_SERVER:-https://galaxy.ansible.com/}" \
--api-key "${{ secrets.ANSIBLE_GALAXY_TOKEN }}" \
"${TARBALL}" 2>&1
);
if [[ $? -ne 0 ]]; then
set -e;
err="Error when publishing collection to cmd_arg .*HTTP Code: 500, Message:";
err500="Internal Server Error Code: Unknown";
if grep -qP "${err} ${err500}" <<< "${publish}"; then
echo "Error found https://github.com/ansible/galaxy/issues/3287, Ignoring...";
echo "${publish}";
ec=0;
else
echo "${publish}";
ec=1;
fi;
exit ${ec}
fi;