Skip to content

Commit

Permalink
Automate release flow
Browse files Browse the repository at this point in the history
  • Loading branch information
thepieterdc committed Oct 17, 2021
1 parent b120a64 commit e0b1170
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 137 deletions.
21 changes: 21 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
changelog:
categories:
- title: "Features :star:"
labels:
- "feature :star:"

- title: "Enhancements :arrow_up:"
labels:
- "enhancement :arrow_up:"

- title: "Bugs :bug:"
labels:
- "bug :bug:"

- title: Dependencies
labels:
- dependencies

- title: Other
labels:
- "*"
74 changes: 46 additions & 28 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,90 +1,108 @@
name: Release

on:
push:
branches:
- 'release/**'
workflow_dispatch:
inputs:
version:
description: Version number
required: true

jobs:
release:
runs-on: ubuntu-latest

permissions:
contents: write
pull-requests: write

steps:
- uses: actions/checkout@v2

- name: Create a release branch
run: |
git checkout -b release
git push -u origin/release
- name: Install Node.js 14.x
uses: actions/setup-node@v2-beta
with:
node-version: '14'
- name: Get the version from package.json
id: version
run: |
echo ::set-output name=version::v$(node scripts/get-version.js)
echo ::set-output name=version-raw::$(node scripts/get-version.js)
- name: Do not release snapshot versions
if: ${{ contains(steps.version.outputs.version, 'SNAPSHOT') }}
run: exit 1
- name: Get the changes in ${{ steps.version.outputs.version }}
id: changelog
run: |
CHANGES=$(node scripts/get-changes.js)
CHANGES="${CHANGES//'%'/'%25'}"
CHANGES="${CHANGES//$'\n'/'%0A'}"
CHANGES="${CHANGES//$'\r'/'%0D'}"
echo "::set-output name=changelog::$CHANGES"

- name: Set the version in package.json
run: node scripts/set-version.js ${{ github.event.inputs.version }}

- name: Create a release commit
uses: EndBug/add-and-commit@v7
with:
add: 'package.json'
message: Release v${{ github.event.inputs.version }}
push: false
signoff: true

- name: Get the Yarn cache directory
id: yarn-cache
run: |
echo "::set-output name=dir::$(yarn cache dir)"
- name: Cache Yarn dependencies
uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Yarn dependencies
run: yarn install

- name: Package the extension
run: yarn package

- name: Create tag
uses: mathieudutour/github-tag-action@v5.5
uses: mathieudutour/github-tag-action@v5.6
with:
custom_tag: v${{ github.event.inputs.version }}
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_tag: ${{ steps.version.outputs.version-raw }}

- name: Create release
id: release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.version.outputs.version }}
release_name: ${{ steps.version.outputs.version }}
body: ${{ steps.changelog.outputs.changelog }}
draft: false
prerelease: false
release_name: v${{ github.event.inputs.version }}
tag_name: v${{ github.event.inputs.version }}

- name: Attach artifact to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.release.outputs.upload_url }}
asset_path: ./dodona-plugin-vscode-${{ steps.version.outputs.version-raw }}.vsix
asset_name: dodona-plugin-vscode-${{ steps.version.outputs.version-raw }}.vsix
asset_content_type: application/octet-stream
asset_name: dodona-plugin-vscode-${{ github.event.inputs.version }}.vsix
asset_path: ./dodona-plugin-vscode-${{ github.event.inputs.version }}.vsix
upload_url: ${{ steps.release.outputs.upload_url }}

- name: Publish to Azure Marketplace
run: yarn run vscode:publish
env:
VSCE_PAT: ${{ secrets.VSCE_PAT }}

- name: Prepare package.json for next version
run: node scripts/prepare-next-snapshot.js

- name: Push new development commit
uses: EndBug/add-and-commit@v7
with:
add: 'package.json'
message: 'Prepare next development cycle'
signoff: true

- name: Open a pull request
uses: repo-sync/pull-request@v2
with:
destination_branch: "master"
github_token: ${{ secrets.GITHUB_TOKEN }}
pr_title: Release ${{ steps.version.outputs.version }}
pr_title: Release v${{ github.event.inputs.version }}
83 changes: 0 additions & 83 deletions CHANGELOG.md

This file was deleted.

7 changes: 0 additions & 7 deletions RELEASING.md

This file was deleted.

15 changes: 0 additions & 15 deletions scripts/get-changes.js

This file was deleted.

4 changes: 0 additions & 4 deletions scripts/get-version.js

This file was deleted.

12 changes: 12 additions & 0 deletions scripts/set-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use strict";

// Sets the next version.
const fs = require("fs");
const packageJson = require("../package.json");

packageJson.version = process.argv[2];

fs.writeFileSync(
`${__dirname}/../package.json`,
JSON.stringify(packageJson, null, 2),
);

0 comments on commit e0b1170

Please sign in to comment.