Skip to content

fix(github-action): extra double quote (#805) #3

fix(github-action): extra double quote (#805)

fix(github-action): extra double quote (#805) #3

Workflow file for this run

---
## Workflow to create a new git tag if version.py variable version gets updated
name: release
permissions:
contents: write # write permission is required to create a GitHub release
on:
push:
branches:
- 'main'
paths:
- 'share/version.py'
jobs:
release:
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
version: ${{ steps.version.outputs.version }}
enabled: ${{ steps.version.outputs.enabled }}
tag: ${{ steps.version.outputs.tag }}
steps:
- uses: actions/checkout@v4
- name: Get version number
shell: bash
run: |
VERSION=$(grep -oE '[0-9]+\.[0-9]+\.[0-9]+(\-[a-zA-Z]+[0-9]+)?' share/version.py)
echo "VERSION=${VERSION}" >> $GITHUB_ENV
echo "::notice::ESF version is $VERSION."
- name: Check if version increased
id: version
shell: bash
run: |
git fetch --tags
# We will list all tags sorted by the version after the prefix lambda-v.
# We retrieve only the first line - that is, the most recent version.
# After that, we remove the prefix to only get the version number.
old_version=$(git tag --list --sort=-version:refname "lambda-v*" | awk 'NR==1{print $1}' | awk -F"lambda-v" '{ print $NF }')
# We now need to compare the current version inside version.py.
IFS='.' read -a new_numbers <<< ${{ env.VERSION }}
IFS='.' read -a old_numbers <<< $old_version
CREATE_TAG=false # only create tag if version increased
for i in 0 1 2
do
if [[ ${new_numbers[i]} > ${old_numbers[i]} ]]
then
CREATE_TAG=true
break
elif [[ ${new_numbers[i]} < ${old_numbers[i]} ]]
then
break
fi
done
echo "CREATE_TAG=${CREATE_TAG}" >> $GITHUB_ENV
echo "::notice::Latest version is $old_version."
echo "::notice::Current version is ${{ env.VERSION }}."
echo "::notice::The result for creating tag is $CREATE_TAG."
echo "version=${{ env.VERSION }}" >> "$GITHUB_OUTPUT"
echo "enabled=${CREATE_TAG}" >> "$GITHUB_OUTPUT"
echo "tag=lambda-v${{ env.VERSION }}" >> "$GITHUB_OUTPUT"
- name: Create tag
if: env.CREATE_TAG == 'true' # run only in case CREATE_TAG is true
uses: actions/github-script@v7
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/' + "${{ steps.version.outputs.tag }}",
sha: context.sha
})
regular-sar:
if: ${{ needs.release.outputs.enabled == 'true' }}
runs-on: ubuntu-latest
needs: release
permissions:
# The OIDC permissions can be found at https://github.com/elastic/oblt-infra/tree/main/conf/resources/repos/elastic-serverless-forwarder
id-token: write
contents: read
env:
BUCKET_NAME : "elastic-serverless-forwarder"
AWS_REGION : "eu-central-1"
# elastic-observability-prod
AWS_ACCOUNT_ID: "267093732750"
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.release.outputs.tag }}
- uses: elastic/oblt-actions/aws/auth@v1
with:
aws-account-id: "${{ env.AWS_ACCOUNT_ID }}"
aws-region: "${{ env.AWS_REGION }}"
- uses: aws-actions/setup-sam@2360ef6d90015369947b45b496193ab9976a9b04 # v2
with:
use-installer: true
token: ${{ secrets.GITHUB_TOKEN }}
- name: Build and package
run: |
.internal/aws/scripts/dist.sh \
elastic-serverless-forwarder \
${{ needs.release.outputs.version }} \
${{ env.BUCKET_NAME }} \
${{ env.AWS_ACCOUNT_ID }} \
${{ env.AWS_REGION }} \
"Elastic"