Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IOCOM-1302] Splitted release action into Bump PR and release #87

Merged
merged 4 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/node-yarn/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runs:
using: "composite"
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version-file: ".node-version"
cache: "yarn"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/anchore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v3
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
- name: Build the Docker image
run: docker build . --file ${{ env.DOCKERFILE }} --tag localbuild/testimage:latest
- name: Run the Anchore scan action itself with GitHub Advanced Security code scanning integration enabled
Expand Down
82 changes: 82 additions & 0 deletions .github/workflows/bump-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Make Release Bump PR

on:
workflow_dispatch:
branches:
- master
inputs:
semver:
required: true
type: choice
description: Select the new Semantic Version
options:
- major
- minor
- patch

jobs:
bump_release:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Input Log
run: |
echo "📝 Inputs"
echo "semver: ${{ inputs.semver }}"
shell: bash

- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Node.js
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version-file: ".node-version"

- id: get_version
name: Get Version
run: |
PACKAGE_FILE="package.json"
if [[ -f "$PACKAGE_FILE" ]]; then
echo "version=$(jq .version package.json)" >> $GITHUB_ENV
fi
shell: bash

- name: Bump Package Version
id: bump
uses: pagopa/github-actions-template/bump-semver@main
with:
semver: ${{ inputs.semver }}
current_version: ${{ env.version }}

- id: semver
name: New Version
run: |
echo "new_version=${{ steps.bump.outputs.new_version}}" >> $GITHUB_OUTPUT
shell: bash

- name: Push New Version to new branch
id: new_branch_push
shell: bash
env:
NEW_BRANCH_NAME: releases/${{ steps.semver.outputs.new_version }}
run: |
contents="$(jq '.version = "${{ steps.semver.outputs.new_version }}"' package.json)"
echo -E "${contents}" > package.json
# Creating new branch for the release
echo "new_branch_name=$NEW_BRANCH_NAME" >> $GITHUB_OUTPUT
git checkout -b $NEW_BRANCH_NAME
git add .
git config --global user.email "[email protected]"
git config --global user.name "pagopa-github-bot"
git commit -m "Bump to version ${{ steps.semver.outputs.new_version }}" || exit 0
git push -u origin $NEW_BRANCH_NAME

- name: Create release pull request
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run:
gh pr create -B main -H ${{ steps.new_branch_push.outputs.new_branch_name }} --title 'Release version ${{ steps.semver.outputs.new_version }} pull request' --body 'This PR has been created by a Github Action' -l 'release'
6 changes: 3 additions & 3 deletions .github/workflows/code-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3

- name: Build app
uses: ./.github/actions/node-yarn
Expand Down Expand Up @@ -41,7 +41,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3

- name: Build app
uses: ./.github/actions/node-yarn
Expand Down Expand Up @@ -69,7 +69,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3

- name: Build app
uses: ./.github/actions/node-yarn
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3

- name: Build app
uses: ./.github/actions/node-yarn
Expand Down
84 changes: 47 additions & 37 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,54 @@
name: Release

on:
workflow_dispatch:
inputs:
release_type:
description: The type of this release
required: true
type: choice
options:
- major
- minor
- patch
# on merge on main branch
pull_request:
types:
- closed
branches:
- master

jobs:
release:
name: Release
runs-on: ubuntu-22.04

build_and_publish:
# run this job only if the PR was containing the specific release label
if: contains( github.event.pull_request.labels.*.name, 'release') || github.event_name == 'workflow_dispatch'
environment: prod-cd
runs-on: ubuntu-latest
permissions:
# contents write permissions required for release
contents: write
packages: write
steps:
- name: Checkout
id: checkout
uses: actions/checkout@1f9a0c22da41e6ebfa534300ef656657ea2c6707

- name: Build app
uses: ./.github/actions/node-yarn

- name: Release
id: release
- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3

- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
registry-url: 'https://registry.npmjs.org'
node-version-file: ".node-version"
# Defaults to the user or organization that owns the workflow file
scope: '@pagopa'

- run: yarn install --frozen-lockfile

- run: yarn build

- id: get_version
name: Get Version
run: |
git config user.email "[email protected]"
git config user.name "pagopa-github-bot"
npm version ${{ inputs.release_type }} --no-git-tag-version
NEXT_VERSION=$(node -p "require('./package.json').version")
RELEASE_TAG="v$NEXT_VERSION-RELEASE"
TITLE="Release $NEXT_VERSION"
git add package.json
git tag $RELEASE_TAG
git commit -m "Bump version to $RELEASE_TAG [skip ci]"
git push origin master && git push --tags
gh release create $RELEASE_TAG --title $TITLE
PACKAGE_FILE="package.json"
if [[ -f "$PACKAGE_FILE" ]]; then
echo "new_version=$(jq -r .version package.json)" >> $GITHUB_ENV
else
echo "::error title=Pipeline error::Pipeline could not find package.json file"
exit 1
fi
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create Release tag
uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5 # v1.14.0
with:
commit: ${{ github.ref_name }}
tag: ${{ env.new_version }}
name: Release ${{ env.new_version }}
makeLatest: latest
generateReleaseNotes: true
prerelease: false
Loading