Publish artifacts and create Github releases #133
Workflow file for this run
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: Publish artifacts and create Github releases | |
on: | |
push: | |
tags: | |
- '[0-9]+.[0-9]+.[0-9]+' | |
- '[0-9]+.[0-9]+.[0-9]+*' | |
workflow_dispatch: | |
env: | |
PRIVATE_DOCKER_REGISTRY_URL: ${{ secrets.GITLAB_DOCKER_REGISTRY_URL }} | |
PRIVATE_DOCKER_REGISTRY_USER: ${{ secrets.GITLAB_PKG_REGISTRY_USER }} | |
PRIVATE_DOCKER_REGISTRY_PASS: ${{ secrets.GITLAB_PKG_REGISTRY_TOKEN }} | |
PRIVATE_MVN_REGISTRY_TOKEN: ${{ secrets.GITLAB_PKG_REGISTRY_TOKEN }} | |
PRIVATE_MVN_REGISTRY_URL: ${{ secrets.GITLAB_MAVEN_REGISTRY_URL }} | |
PRIVATE_MVN_REGISTRY_USER: ${{ secrets.GITLAB_PKG_REGISTRY_USER }} | |
PRIVATE_MVN_REGISTRY_PASS: ${{ secrets.GITLAB_PKG_REGISTRY_TOKEN }} | |
DOCKER_PUSH: false | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
publish: | |
permissions: | |
contents: write | |
packages: write | |
runs-on: self-hosted | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.COMMIT_PAT_TOKEN }} | |
- name: ⛮ cf-gha-baseline | |
uses: cardano-foundation/cf-gha-workflows/./actions/cf-gha-baseline@main | |
with: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
PRIVATE_DOCKER_REGISTRY_URL: ${{ env.PRIVATE_DOCKER_REGISTRY_URL }} | |
PRIVATE_DOCKER_REGISTRY_USER: ${{ env.PRIVATE_DOCKER_REGISTRY_USER }} | |
PRIVATE_DOCKER_REGISTRY_PASS: ${{ env.PRIVATE_DOCKER_REGISTRY_PASS }} | |
HUB_DOCKER_COM_USER: ${{ secrets.HUB_DOCKER_COM_USER }} | |
HUB_DOCKER_COM_PASS: ${{ secrets.HUB_DOCKER_COM_PASS }} | |
DOCKER_REGISTRIES: "${{ secrets.DOCKER_REGISTRIES }}" | |
- name: Set extra environment and metadata | |
id: metadata | |
run: | | |
GRADLE_PROPERTIES_VERSION=$(grep version gradle.properties | awk '{print $NF}') | |
echo "GITHUB_EVENT_NAME: ${GITHUB_EVENT_NAME}" | |
# if a tag triggered the build, use the tag to set the version in gradle.properties | |
case "${GITHUB_EVENT_NAME}" in | |
push) | |
if [ "${TRIGGERING_REF}" == "tag" ] | |
then | |
# fail if tag differs from what's set for gradle | |
if [ "${TAG_NAME}" != "${GRADLE_PROPERTIES_VERSION}" ] | |
then | |
echo "[!] Tag name doesn't match gradle.properties version. Please commit the proper version and retag." | |
exit 1 | |
fi | |
# Add 'latest' tag to the list of tags to push | |
EARTHLY_DOCKER_IMAGES_EXTRA_TAGS="${EARTHLY_DOCKER_IMAGES_EXTRA_TAGS} ${TAG_NAME} latest" | |
# Set target docker registries to every registry in the secret | |
echo "DOCKER_REGISTRIES=${{ secrets.DOCKER_REGISTRIES }}" | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_OUTPUT" | |
# Set the next snapshot version that will be auto-commited to the main branch | |
NEXT_SNAPSHOT_VERSION=$(echo $GRADLE_PROPERTIES_VERSION | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g') | |
echo "NEXT_SNAPSHOT_VERSION=${NEXT_SNAPSHOT_VERSION}" | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_OUTPUT" | |
fi | |
;; | |
workflow_dispatch) | |
if [[ "${GRADLE_PROPERTIES_VERSION}" =~ .*-SNAPSHOT$ ]] | |
then | |
echo "[!] gradle.properties version is not a SNAPSHOT version. Please fix it and relaunch this job." | |
exit 1 | |
fi | |
# Set target docker registries to only use the private registry | |
echo "DOCKER_REGISTRIES=${PRIVATE_DOCKER_REGISTRY_URL}" | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_OUTPUT" | |
EARTHLY_DOCKER_IMAGES_EXTRA_TAGS="${EARTHLY_DOCKER_IMAGES_EXTRA_TAGS} ${GRADLE_PROPERTIES_VERSION}" | |
;; | |
*) | |
echo "[!] Unsupported event name for this workflow: ${GITHUB_EVENT_NAME}" | |
exit 1 | |
esac | |
echo "GRADLE_PROPERTIES_VERSION=${GRADLE_PROPERTIES_VERSION}" | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_OUTPUT" | |
echo "EARTHLY_DOCKER_IMAGES_EXTRA_TAGS=${EARTHLY_DOCKER_IMAGES_EXTRA_TAGS}" | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_OUTPUT" | |
- name: 🌍 earthly - gradle build | |
run: | | |
earthly +gradle-build | |
- name: 🌍 earthly - docker build and push | |
run: | | |
earthly +docker-publish \ | |
--PUSH=${DOCKER_PUSH} \ | |
--DOCKER_REGISTRIES="${DOCKER_REGISTRIES}" \ | |
--DOCKER_IMAGES_EXTRA_TAGS="${EARTHLY_DOCKER_IMAGES_EXTRA_TAGS}" | |
- name: Create Github release and upload jar files | |
if: github.ref_type == 'tag' | |
uses: softprops/action-gh-release@v2 | |
with: | |
prerelease: true | |
files: | | |
release/* | |
- name: Bump versions | |
if: github.ref_type == 'tag' | |
run: | | |
# Bump version only if tag's commit belongs to main branch | |
if [ $(git for-each-ref | grep ^${GIT_SHORT_COMMIT} | grep refs.remotes.origin | sed 's|.*refs/remotes/origin/\(.*\)|\1|' | grep -c ^main$) -gt 0 ] | |
then | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
git fetch --all --tags | |
sed -i "s|^version.*|version = ${NEW_ARTIFACT_SNAPSHOT_VERSION}-SNAPSHOT|" gradle.properties | |
git commit gradle.properties -m "chore(gradle): Bump version to ${NEW_ARTIFACT_SNAPSHOT_VERSION}-SNAPSHOT (automated commit by gha run id $GITHUB_RUN_ID)" | |
sed -i "s|image: \${CF_LEDGER_SYNC_DOCKER_IMAGE:-cardanofoundation/cf-ledger-sync:latest}| image: \${CF_LEDGER_SYNC_DOCKER_IMAGE:-cardanofoundation/cf-ledger-sync:${ARTIFACT_VERSION}}|" docker-compose.yaml | |
git commit docker-compose.yaml -m "chore(docker-compose): Bump image version to ${ARTIFACT_VERSION} (automated commit by gha run id $GITHUB_RUN_ID)" | |
TAG_BRANCH=main | |
git push origin HEAD:${TAG_BRANCH} | |
fi |