Skip to content

Commit

Permalink
Change versioning (#48)
Browse files Browse the repository at this point in the history
* Change versioning

The current versioning is considered pre-release. Switching to use a
slightly different format to make every release a patch release.

The version of the patch release is now the epoch of the latest commit
date merged into main

Before: 0.2.1-{%Y%m%D%H%M}git{SHA}
Now: 0.2.{%s}+{%Y%m%D%H%M}.git{SHA}

The + delimits the version from metadata for the release

* Build and push manually

Due to ansible/galaxy#3287 can't run the GHA
ansible/ansible-publish-action without failing, despite the error 500,
the collection is published, we are ignoring the 500 until fixed.
  • Loading branch information
tonyskapunk authored Nov 20, 2023
1 parent 137c9ed commit 9239258
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
38 changes: 30 additions & 8 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,37 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Add release, date and commit hash to version in galaxy.yml
- name: Add epoch from commit date as patch version and metadata in galaxy.yml
run: >
ts=$(TZ=UTC0 git show ${{ github.sha }} --no-patch --format=%cd --date=format-local:'%Y%m%d%H%M')
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);
rel=$(grep ^Release ansible-collection-redhatci-ocp.spec | grep -Po '\d+\.');
sed -i -r "s/^(version: .*)$/&-${rel}${ts}git${sha}/" galaxy.yml;
sed -i -r "s/^(version: .*)\.0$/\1.${z}+${ts}.git${sha}/" galaxy.yml;
grep ^version galaxy.yml
- name: Ansible Publish to Galaxy
uses: ansible/[email protected]
with:
api_key: ${{ secrets.ANSIBLE_GALAXY_TOKEN }}
# 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);
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
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;
4 changes: 4 additions & 0 deletions galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ namespace: redhatci
name: ocp

# The version of the collection. Must be compatible with semantic versioning
# Always leave patch version as .0
# Patch version is replaced from commit date in epoch format
# Metadata is included to add commit date and git hash
# example: 0.2.2147483647+203801190314.git0a1b2c3
version: 0.2.0

# The path to the Markdown (.md) readme file.
Expand Down

0 comments on commit 9239258

Please sign in to comment.