Skip to content

fix: use env vars, second try #101

fix: use env vars, second try

fix: use env vars, second try #101

Workflow file for this run

name: Release
on:
push:
branches:
- master
jobs:
setup_release:
name: Prepare release
permissions:
contents: write
issues: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: cache NPM
uses: actions/[email protected]
id: npm-cache
with:
path: |
**/node_modules
${{ needs.install.outputs.npm-cache-dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Setup Node.js environment
uses: actions/[email protected]
with:
node-version: "lts/*"
- name: Install dependencies
run: npm ci
- name: next release version
id: next_release_version
run: |
export NEXT_TAG_VERSION=$(npx semantic-release --dry-run | grep 'The next release version is' | sed -E 's/.* ([[:digit:].]+)$/\1/')
echo "new_tag_version=${NEXT_TAG_VERSION}" >> $GITHUB_OUTPUT
echo "new_tag_version=${NEXT_TAG_VERSION}"
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
outputs:
new_tag_version: ${{ steps.next_release_version.outputs.new_tag_version }}
process_gradle_build:
name: Process build.gradle
needs: setup_release
if: ${{ needs.setup_release.outputs.new_tag_version != '' }}
runs-on: ubuntu-latest
env:
FILE: app/build.gradle
VERSION_REGEX: version\s*=\s*'[0-9]\\+\\.[0-9]\\+\\.[0-9]\\+'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Print orig file
run: |
cat ${{ env.FILE }}
- name: Update version and date in file
if: ${{needs.setup_release.outputs.new_tag_version != ''}}
run: |
VERSION=${{ needs.setup_release.outputs.new_tag_version }}
sed -i "s/${{ env.VERSION_REGEX }}/version = '$VERSION'/g" ${{ env.FILE }}
- name: Print new file
if: ${{needs.setup_release.outputs.new_tag_version != ''}}
run: |
cat ${{ env.FILE }}
- name: Upload updated file
uses: actions/upload-artifact@v4
with:
name: updated-build-gradle
path: ${{ env.FILE }}
process_test_adoc:
name: Process test.adoc
needs: setup_release
if: ${{ needs.setup_release.outputs.new_tag_version != '' }}
runs-on: ubuntu-latest
env:
FILE: test.adoc
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Print orig file
run: |
cat ${{ env.FILE }}
- name: Update version and date in file
if: ${{needs.setup_release.outputs.new_tag_version != ''}}
run: |
echo "new_tag_version=${{ needs.setup_release.outputs.new_tag_version }}"
# Get the version from the output of the Semantic Release step
VERSION=${{ needs.setup_release.outputs.new_tag_version }}
# Get the current date
DATE=$(date +%Y-%m-%d)
# Regular expression to match the string to be replaced
REGEX="v[0-9]\+\.[0-9]\+\.[0-9]\+\, [0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}"
# Replace the string in file
sed -i "s/$REGEX/v$VERSION, $DATE/g" $FILE
- name: Print new file
if: ${{needs.setup_release.outputs.new_tag_version != ''}}
run: |
cat ${{ env.FILE }}
- name: Upload updated file
uses: actions/upload-artifact@v4
with:
name: updated-test-adoc
path: ${{ env.FILE }}
process_file2_md:
name: Process file2.md
needs: setup_release
if: ${{ needs.setup_release.outputs.new_tag_version != '' }}
runs-on: ubuntu-latest
env:
FILE: file2.md
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Print orig file
run: |
cat ${{ env.FILE }}
- name: Update version and date in file
if: ${{needs.setup_release.outputs.new_tag_version != ''}}
run: |
echo "new_tag_version=${{ needs.setup_release.outputs.new_tag_version }}"
# Get the version from the output of the Semantic Release step
VERSION=${{ needs.setup_release.outputs.new_tag_version }}
# Get the current date
DATE=$(date +%Y-%m-%d)
# Regular expression to match the string to be replaced
REGEX="v[0-9]\+\.[0-9]\+\.[0-9]\+\, [0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}"
# Replace the string in file
sed -i "s/$REGEX/v$VERSION, $DATE/g" $FILE
- name: Print new file
if: ${{needs.setup_release.outputs.new_tag_version != ''}}
run: |
cat ${{ env.FILE }}
- name: Upload updated file
uses: actions/upload-artifact@v4
with:
name: updated-file2-md
path: ${{ env.FILE }}
complete_release:
name: Complete release
needs: [setup_release, process_test_adoc, process_file2_md, process_gradle_build]
if: ${{ needs.setup_release.outputs.new_tag_version != '' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Download updated updated-build-gradle
uses: actions/download-artifact@v4
with:
name: updated-build-gradle
- name: Download updated test.adoc
uses: actions/download-artifact@v4
with:
name: updated-test-adoc
- name: Download updated file2.md
uses: actions/download-artifact@v4
with:
name: updated-file2-md
- name: Print build.gradle
run: |
echo "Updated build.gradle"
cat app/build.gradle
- name: cache NPM
uses: actions/[email protected]
id: npm-cache
with:
path: |
**/node_modules
${{ needs.install.outputs.npm-cache-dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Setup Node.js environment
uses: actions/[email protected]
with:
node-version: "lts/*"
- name: Install dependencies
run: npm ci
- name: Release with next Semantic Version
id: release_with_next_semantic_version
if: ${{needs.setup_release.outputs.new_tag_version != ''}}
run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
GIT_COMMITTER_NAME: "Arc-E-Tect"
GIT_COMMITTER_EMAIL: "[email protected]"
GIT_AUTHOR_NAME: "Arc-E-Tect"
GIT_AUTHOR_EMAIL: "[email protected]"
- name: No release with next Semantic Version
if: ${{needs.setup_release.outputs.new_tag_version == ''}}
run: echo "No new release required..."