Release #31
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: Release | |
on: | |
workflow_dispatch: | |
inputs: | |
title: | |
description: "Release title" | |
required: false | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
environment: deployment | |
name: Build, publish, release, and announce | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ssh-key: ${{ secrets.DEPLOY_KEY }} | |
- name: Install node 20 | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
cache: npm | |
- name: Configure git | |
run: | | |
git config user.name "${{ github.actor }}" | |
git config user.email "${{ github.actor }}@users.noreply.github.com" | |
- name: Configure aws | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
- name: Determine next SemVer | |
id: bumper | |
uses: tomerfi/[email protected] | |
- name: Update package with new version | |
run: | | |
npm version ${{ steps.bumper.outputs.next }} --no-git-tag-version | |
- name: Install project modules | |
run: npm ci --production | |
- name: Create lambda archive | |
run: zip -r auto-me-bot.zip src/ node_modules/ package.json package-lock.json | |
- name: Get function state | |
id: function_state | |
run: | | |
state=$(aws lambda get-function --function-name ${{ secrets.LAMBDA_FUNCTION }} --query 'Configuration.State' --output text) | |
echo "state=$state" >> $GITHUB_OUTPUT | |
- name: Verify function is in active state | |
if: steps.function_state.outputs.state != 'Active' | |
uses: actions/github-script@v7 | |
with: | |
script: core.setFailed('the function is being updated, please try again later') | |
- name: Deploy archive to lambda | |
run: > | |
aws lambda update-function-code | |
--function-name ${{ secrets.LAMBDA_FUNCTION }} | |
--zip-file fileb://./auto-me-bot.zip | |
- name: Wait for function to be updated | |
run: aws lambda wait function-updated --function-name ${{ secrets.LAMBDA_FUNCTION }} | |
- name: Publish lambda function | |
id: publish_lambda | |
run: | | |
set -o pipefail | |
function_version=$( aws lambda publish-version --function-name ${{ secrets.LAMBDA_FUNCTION }} | jq -r ".Version" ) | |
echo "function_version=$function_version" >> $GITHUB_OUTPUT | |
- name: Update alias Live with new function version | |
run: > | |
aws lambda update-alias | |
--function-name ${{ secrets.LAMBDA_FUNCTION }} | |
--name Live | |
--function-version ${{ steps.publish_lambda.outputs.function_version }} | |
- name: Commit and push package modifications | |
run: | | |
git add package.json | |
git add package-lock.json | |
git commit -m "docs: updated package with ${{ steps.bumper.outputs.next }} [skip ci]" | |
git push | |
- name: Create and push new tag | |
run: | | |
git tag ${{ steps.bumper.outputs.next }} -m "Function v${{ steps.publish_lambda.outputs.function_version }}" | |
git push origin ${{ steps.bumper.outputs.next }} | |
- name: Create a release name | |
id: release_name | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
var retval = '${{ steps.bumper.outputs.next }}' | |
if ('${{ github.event.inputs.title }}') { | |
retval = retval.concat(' - ${{ github.event.inputs.title }}') | |
} | |
core.setOutput('value', retval) | |
- name: Create a release | |
id: gh_release | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.RELEASE_PAT }} | |
script: | | |
const repo_name = context.payload.repository.full_name | |
const response = await github.request('POST /repos/' + repo_name + '/releases', { | |
tag_name: '${{ steps.bumper.outputs.next }}', | |
name: '${{ steps.release_name.outputs.value }}', | |
generate_release_notes: true | |
}) | |
core.setOutput('html_url', response.data.html_url) | |
- name: Update documentation with new version | |
run: | | |
sed -i 's/ version: .*/ version: "${{ steps.bumper.outputs.next }}"/g' mkdocs.yml | |
- name: Commit and push docs modifications | |
run: | | |
git add mkdocs.yml | |
git commit -m "docs: updated docs with ${{ steps.bumper.outputs.next }} [skip ci]" | |
git push |