Skip to content

Publish new images for "main" triggered by kacperzuk-neti #2

Publish new images for "main" triggered by kacperzuk-neti

Publish new images for "main" triggered by kacperzuk-neti #2

name: Publish new build
run-name: Publish new images for "${{ github.ref_name }}" triggered by ${{ github.actor }}
on:
pull_request:
types: [opened, synchronize]
push:
branches:
- main
workflow_dispatch:
inputs:
version:
description: 'Enter the version number'
required: true
default: 'latest'
jobs:
format-and-lint:
uses: ./.github/workflows/code-check.yml
bump-version:
runs-on: ubuntu-latest
needs: format-and-lint
if: ${{ github.ref_name == 'main' && inputs.version != '' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Git config
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
- name: Install semver
run: npm install semver
- name: Get current version
run: echo "current_version=$(jq -r '.version' package.json)" >> $GITHUB_ENV
- name: Validate and set new version
run: |
new_version="${{ inputs.version }}"
current_version="${{ env.current_version }}"
if npx semver $new_version -r "<=$current_version"; then
echo "Error: New version ($new_version) is lowest or the same as current ($current_version)"
exit 1
fi
- name: Bump version
run: |
npm version ${{ inputs.version }} --no-git-tag-version
- name: Commit version change
run: |
git commit -am "Update version to ${{ inputs.version }}"
git push origin main
staging-only-publish:
uses: ./.github/workflows/build-docker-image.yml
needs:
- format-and-lint
- bump-version
if: |
always() &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled')
with:
environment: staging-fidl
secrets: inherit
production-only-publish:
needs:
- format-and-lint
- bump-version
uses: ./.github/workflows/build-docker-image.yml
if: |
${{ github.ref_name == 'main' && inputs.version != '' }} &&
always() &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled')
with:
environment: production-fidl
version: ${{ inputs.version }}
secrets: inherit
git-tag:
runs-on: ubuntu-latest
needs:
- staging-only-publish
- production-only-publish
if: |
${{ github.ref_name == 'main' && inputs.version != '' }} &&
always() &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create and push tag
run: |
TAG_NAME="v${{ inputs.version }}"
git tag $TAG_NAME
git push origin $TAG_NAME