Creating github actions workflow with publishing pipeline #4
This file contains hidden or 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: Build and Release | |
on: | |
push: | |
branches: [ fabisev/artifact-publishing ] | |
tags: [ 'v*' ] | |
pull_request: | |
branches: [ main ] | |
jobs: | |
# lint: | |
# runs-on: ubuntu-latest | |
# steps: | |
# - uses: actions/checkout@v4 | |
# - name: Setup Node.js | |
# uses: actions/setup-node@v4 | |
# with: | |
# node-version: '20' | |
# cache: 'npm' | |
# - name: Install and lint | |
# run: | | |
# npm ci | |
# npm run lint | |
# npm run format | |
build: | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.version.outputs.version }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
cache: 'npm' | |
- name: Get version | |
id: version | |
run: | | |
BASE_VERSION=$(node -p "require('./package.json').version") | |
VERSION="${BASE_VERSION}" | |
echo "version=$VERSION" >> $GITHUB_OUTPUT | |
- name: Cache native dependencies | |
uses: actions/cache@v4 | |
with: | |
path: | | |
deps/ | |
build/ | |
key: native-deps-${{ runner.os }}-${{ hashFiles('deps/versions', 'binding.gyp') }} | |
- name: Install and build | |
run: | | |
npm ci | |
npm run build | |
npm pack | |
- name: Generate checksums and signatures | |
run: | | |
PACKAGE_FILE=$(ls aws-lambda-ric-*.tgz) | |
sha256sum $PACKAGE_FILE > checksums.sha256 | |
sha512sum $PACKAGE_FILE > checksums.sha512 | |
cat checksums.sha256 checksums.sha512 > checksums.txt | |
echo "Package: $PACKAGE_FILE with version prefix: ${{ steps.version.outputs.version }}" >> checksums.txt | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: package-${{ steps.version.outputs.version }} | |
path: | | |
aws-lambda-ric-*.tgz | |
checksums.* | |
retention-days: 30 | |
test: | |
runs-on: ubuntu-latest | |
needs: [build] #don't forget to add lint later | |
strategy: | |
matrix: | |
node-version: [18, 20, 22] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Run unit tests - Node ${{ matrix.node-version }} | |
run: | | |
docker build -f test/unit/Dockerfile.nodejs${{ matrix.node-version }}.x -t unit/nodejs.${{ matrix.node-version }}x . | |
docker run --rm unit/nodejs.${{ matrix.node-version }}x | |
publish: | |
if: startsWith(github.ref, 'refs/tags/v') | |
runs-on: ubuntu-latest | |
needs: [build, test] | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Download artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: package-${{ needs.build.outputs.version }} | |
- name: Verify checksums | |
run: | | |
sha256sum -c checksums.sha256 | |
sha512sum -c checksums.sha512 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
registry-url: 'https://registry.npmjs.org' | |
# - name: Publish to npm | |
# run: npm publish aws-lambda-ric-*.tgz | |
# env: | |
# NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Create GitHub Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
files: | | |
aws-lambda-ric-*.tgz | |
checksums.sha256 | |
checksums.sha512 | |
checksums.txt | |
generate_release_notes: true |