Skip to content

Commit

Permalink
Use new actions-lib for ci (#57)
Browse files Browse the repository at this point in the history
* feat: use new actions-lib for ci

* feat: use default gh token for dependency resolution

* feat: remove unused sonar-token ref
  • Loading branch information
joakimen authored Jan 31, 2024
1 parent b126b0c commit 31bfa19
Showing 1 changed file with 50 additions and 55 deletions.
105 changes: 50 additions & 55 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,77 +6,72 @@ on:

defaults:
run:
shell: bash
# NOTE: A bit stricter than the default bash options used by GitHub Actions
# (bash --noprofile --norc -e -o pipefail {0})
shell: bash --noprofile --norc -euo pipefail {0}

# NOTE: Set concurrency for the current workflow to 1
concurrency: ci-${{ github.ref }}-${{ github.workflow }}

jobs:
get-runner-user:
runs-on: ubuntu-22.04
outputs:
uid_gid: ${{ steps.get-user.outputs.uid_gid }}
steps:
- id: get-user
run: echo "uid_gid=$(id -u):$(id -g)" >> "$GITHUB_OUTPUT"
build-and-deploy:
needs: get-runner-user
build-and-release:
runs-on: ubuntu-22.04
container:
image: "public.ecr.aws/z8l5l4v4/buildtools/tool/maven:3-jdk-11-debian"
options: --user ${{ needs.get-runner-user.outputs.uid_gid }}
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v3

- uses: actions/setup-java@v4
with:
distribution: "zulu"
java-version: "11.0.22"
java-package: "jdk"

- uses: capralifecycle/actions-lib/check-runtime-dependencies@v1

- name: cache mvn
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: maven-${{ hashFiles('**/pom.xml') }}
restore-keys: maven-
- name: store branch name in environment
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF##*/})" >> "$GITHUB_ENV"
- name: git config
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: release preparation
id: prep
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: configure maven
run: |
mkdir -p "$HOME/.m2"
cat <<EOF > "$HOME/.m2/settings.xml"
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>github</id>
<username>\${env.GITHUB_ACTOR}</username>
<password>\${env.GITHUB_TOKEN}</password>
</server>
</servers>
</settings>
EOF
major_version="$(sed -n "s/^.*<major-version>\([0-9]\{1,\}\)<\/major-version>.*$/\1/p" pom.xml)"
echo "$major_version" | grep -q "^[0-9]\{1,\}$" || {
echo "ERROR: Failed to extract <major-version> from pom.xml"
exit 1
}
echo "major-version=$major_version" >> "$GITHUB_OUTPUT"
- uses: capralifecycle/actions-lib/generate-tag@v1
id: tag
with:
tag-prefix: "${{ steps.prep.outputs.major-version }}"
tag-type: "punctuated-timestamp-tag"

- name: resolve dependencies
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: mvn -B dependency:resolve

- name: conditional release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
export MAVEN_OPTS="-Duser.home=$HOME" # Home directory not automatically picked up for some reason
major_version="$(sed -n "s/^.*<major-version>\([0-9]\{1,\}\)<\/major-version>.*$/\1/p" pom.xml)"
date="$(date -u "+%Y%m%d.%H%M%S")"
tag="$major_version.$date"
printf "Tag to use for potential release: %s\n" "$tag"
mvn -B org.apache.maven.plugins:maven-enforcer-plugin:3.0.0-M3:enforce -Drules=requireReleaseDeps
CONDITIONAL_RELEASE: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
TAG: "${{ steps.tag.outputs.tag }}"

release="false"
git fetch --tags
if [ "$BRANCH_NAME" = "master" ]; then
latest_tag="$(git describe --abbrev=0 || true)"
latest_tag_commit="$(if test -n "$latest_tag"; then git rev-parse "$latest_tag^{}"; fi)"
if [ ! "$latest_tag_commit" = "$GITHUB_SHA" ]; then
release="true"
fi
fi
if [ "$release" = "true" ]; then
# Release to GitHub Packages
mvn -B source:jar deploy scm:tag -DaltReleaseDeploymentRepository="github::default::https://maven.pkg.github.com/capralifecycle/liflig-properties" -Drevision="$tag" -Dtag="$tag"
run: |
if [ "$CONDITIONAL_RELEASE" = "true" ]; then
echo "Releasing library with tag '$TAG'"
mvn -B source:jar deploy scm:tag -Drevision="$TAG" -Dtag="$TAG" \
org.apache.maven.plugins:maven-enforcer-plugin:3.0.0-M3:enforce -Drules=requireReleaseDeps
else
mvn -B source:jar verify -Drevision="$tag" -Dtag="$tag"
mvn -B -U verify
fi

0 comments on commit 31bfa19

Please sign in to comment.