Skip to content

Stage

Stage #53

Workflow file for this run

---
name: Stage
on:
workflow_dispatch:
push:
branches:
- master
paths-ignore:
- '**/*.md'
- .github/workflows/**
jobs:
build:
runs-on: ubuntu-latest
if: github.repository_owner == 'fabric8-analytics'
name: Build plugin
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ssh-key: ${{ secrets.DEPLOY_KEY }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
registry-url: 'https://npm.pkg.github.com'
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create .npmrc
run: |
echo "@RHEcosystemAppEng:registry=https://npm.pkg.github.com" > ~/.npmrc
echo "@fabric8-analytics:registry=https://npm.pkg.github.com" >> ~/.npmrc
- name: Install @vscode/vsce
run: npm i -g @vscode/vsce
- name: Install Dependencies
run: npm ci
- name: Compile for test
run: npm run test-compile
- name: VSCE package
run: vsce package --out fabric8-analytics-early-access.vsix
- name: Upload vsix package as artifact
uses: actions/upload-artifact@v3
with:
name: vsix
path: ./fabric8-analytics-early-access.vsix
release:
permissions: write-all
runs-on: ubuntu-latest
name: Create an early-access release
environment: staging
needs: build
steps:
- name: Checkout sources
uses: actions/checkout@v3
with:
ssh-key: ${{ secrets.DEPLOY_KEY }}
- name: Configure git
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
- name: Update package with new version
id: bump
run: |
echo "version=$(npm version ${{ vars.VERSION_BUMPING_TYPE }} --no-git-tag-version)" >> "$GITHUB_OUTPUT"
- name: Create release notes from changelog
id: release-notes
run: |
version="${{ steps.bump.outputs.version }}"
version=${version#v}
notes=$(sed -n "/## $version/,/^##/p" ./CHANGELOG.md | grep -v '##')
if [ -z "$notes" ]; then
echo "Release notes are missing for version $version."
exit 1
else
echo "version=$version" >> "$GITHUB_OUTPUT"
notes="${notes//$''/%27}"
notes="${notes//$''/%60}"
notes="${notes//$'\n'/'%0A'}"
notes="${notes//$'\r'/'%0D'}"
delimiter="$(openssl rand -hex 8)"
echo "notes<<${delimiter}" >> "$GITHUB_OUTPUT"
echo "$notes" >> "$GITHUB_OUTPUT"
echo "${delimiter}" >> "$GITHUB_OUTPUT"
fi
- name: Update current version date in changelog
run: |
day_suffix=$(date +"%e" | sed 's/^[[:space:]]*//')
if [ "$day_suffix" = "1" ] || [ "$day_suffix" = "21" ] || [ "$day_suffix" = "31" ]; then
suffix="st"
elif [ "$day_suffix" = "2" ] || [ "$day_suffix" = "22" ]; then
suffix="nd"
elif [ "$day_suffix" = "3" ] || [ "$day_suffix" = "23" ]; then
suffix="rd"
else
suffix="th"
fi
today="$(date +"%b %-d")$suffix $(date +"%Y")"
version="${{ steps.release-notes.outputs.version }}"
if grep -qE "## $version \([^)]*\)" ./CHANGELOG.md; then
current_date=$(grep -oP "(?<=## $version \()[^\)]*" ./CHANGELOG.md)
if [ "$current_date" != "$today" ]; then
sed -E -i "s/## $version \([^)]*\)/## $version ($today)/" CHANGELOG.md
fi
else
sed -E -i "s/## $version/## $version ($today)/" CHANGELOG.md
fi
- name: Download vsix package artifact
uses: actions/download-artifact@v3
with:
name: vsix
path: ./vsix
- name: Commit and push package modifications
run: |
git add CHANGELOG.md
git add package.json
git add package-lock.json
git commit -m "build: updated package with ${{ steps.bump.outputs.version }} [skip ci]"
git push
- name: Create and push new tag
run: |
git tag ${{ steps.bump.outputs.version }} -m "${{ steps.bump.outputs.version }}"
git push origin ${{ steps.bump.outputs.version }}
- name: Create a release
id: new_release
uses: actions/github-script@v6.4.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const repo_name = context.payload.repository.full_name
const response = await github.request('POST /repos/' + repo_name + '/releases', {
tag_name: '${{ steps.bump.outputs.version }}',
name: '${{ steps.bump.outputs.version }}',
body: '${{ steps.release-notes.outputs.notes }}',
prerelease: false,
generate_release_notes: true
})
core.setOutput('upload_url', response.data.upload_url)
- name: Create SHA256 checksums for the binaries
working-directory: vsix
run: |
for pkg in *
do
sha256sum "$pkg" > "$pkg.sha256"
done
- name: Upload packages and checksums as early-access release assets
working-directory: vsix
run: |
for file in *
do
asset_name=$(basename "$file")
upload_url=$(echo "${{ steps.new_release.outputs.upload_url }}" | sed "s/{?name,label}/?name=$asset_name/g")
curl --data-binary @"$file" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/octet-stream" \
"$upload_url"
done