Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleffio committed Sep 20, 2023
1 parent 7c9ddad commit 7773abb
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- uses: actions/checkout@v3

- name: Set Node.js 16.x
uses: actions/setup-node@v3.6.0
uses: actions/setup-node@v3.8.1
with:
node-version: 16.x

Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/github-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ on:
workflow_dispatch:
push:
branches:
- releases/v1
- main
paths:
- VERSION

jobs:
v1:
github:
permissions:
contents: write
uses: ./.github/workflows/reusable-github-release.yml
with:
release-title: Release Automation Action
develop-branch: main
release-branch: releases/v1
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
11 changes: 8 additions & 3 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
name: Prepare release

on:
push:
workflow_dispatch:
pull_request:
types:
- closed
- labeled
- unlabeled
branches:
- main

jobs:
v1:
candidate:
if: github.event_name == 'workflow_dispatch' || (github.event.pull_request.merged && !startsWith(github.head_ref, 'promote/'))
permissions:
contents: write
pull-requests: write
Expand All @@ -18,5 +24,4 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}
develop-branch: main
release-branch: releases/v1
version-files: package.json
11 changes: 1 addition & 10 deletions .github/workflows/reusable-github-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ on:
required: true
type: string
develop-branch:
description: 'Branch used for development'
required: true
type: string
release-branch:
description: 'Branch used for distribution'
description: 'Branch used for development and distribution'
required: true
type: string

Expand All @@ -42,8 +38,3 @@ jobs:
gh release create "v${CURRENT_VERSION}" \
--title "${{ inputs.release-title }} v${CURRENT_VERSION}" \
--generate-notes $prerelease --target ${{ inputs.release-branch }}
- name: Update development branch
run: |
git checkout ${{ inputs.develop-branch }}
git rebase origin/${{ inputs.release-branch }}
git push origin ${{ inputs.develop-branch }}
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ jobs:
contents: write
pull-requests: write
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
- name: Integration test
uses: ./
with:
token: ${{ secrets.GITHUB_TOKEN }}
pre-release: true
develop-branch: main
release-branch: beta
version-files: README.md package.json
develop-branch: beta
version-files: README.md package.json
22 changes: 19 additions & 3 deletions __tests__/release.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,22 @@ const comparisonFixture: release.Comparison = {
}
}

const refNotFound: release.Comparison = {
repository: {name: 'adyen-cobol-api-library', ref: null}
}

test('Changelog', () => {
const changelog = release.changelog(comparisonFixture)

expect(changelog).toStrictEqual(['- #10', '- #20', '- #30'])
})

test('Changelog null ref', () => {
const changelog = release.changelog(refNotFound)

expect(changelog).toStrictEqual([])
})

describe('Detect changes', () => {
test('Major', () => {
const ver = release.detectChanges(comparisonFixture)
Expand All @@ -117,16 +127,22 @@ describe('Detect changes', () => {

test('Zero changes', () => {
let sync = structuredClone(comparisonFixture)
sync.repository.ref.compare.aheadBy = 0
sync.repository.ref!.compare.aheadBy = 0

const ver = release.detectChanges(sync)

expect(ver).toBe('')
})

test('Ref not found', () => {
const ver = release.detectChanges(refNotFound)

expect(ver).toBe('')
})

test('No labels', () => {
let noLabels = structuredClone(comparisonFixture)
for (const edge of noLabels.repository.ref.compare.commits.edges) {
for (const edge of noLabels.repository.ref!.compare.commits.edges) {
for (const prs of edge.node.associatedPullRequests.edges) {
prs.node.labels.nodes = []
}
Expand Down Expand Up @@ -230,4 +246,4 @@ test('Bump', async () => {
expect(core.setOutput).toHaveBeenCalledTimes(3)
expect(core.setOutput).toHaveBeenCalledWith('increment', 'major')
expect(core.setOutput).toHaveBeenCalledWith('next-version', '2.0.0')
})
})
24 changes: 9 additions & 15 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ inputs:
description: 'This release will be labeled as non-production ready'
default: false
develop-branch:
description: 'Branch used for development'
description: 'Branch used for development and distribution'
default: develop
release-branch:
description: 'Branch used to publish releases of the `develop-branch`'
default: main
version-files:
description: 'Files to bump with the new version'
required: false
Expand All @@ -27,14 +24,6 @@ outputs:
runs:
using: "composite"
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.release-branch }}
- name: Reset promotion branch
run: |
git fetch origin ${{ inputs.develop-branch }}:${{ inputs.develop-branch }}
git reset --hard ${{ inputs.develop-branch }}
shell: bash
- name: Grab current version
id: current-version
run: echo "current-version=$(cat VERSION)" >> $GITHUB_OUTPUT
Expand All @@ -47,24 +36,29 @@ runs:
INPUT_TOKEN: ${{ inputs.token }}
INPUT_PRE-RELEASE: ${{ inputs.pre-release }}
INPUT_DEVELOP-BRANCH: ${{ inputs.develop-branch }}
INPUT_RELEASE-BRANCH: ${{ inputs.release-branch }}
INPUT_CURRENT-VERSION: ${{ steps.current-version.outputs.current-version }}
- name: Bump
run: |
perl -i -pe 's/${{steps.current-version.outputs.current-version}}/${{steps.release.outputs.next-version}}/' VERSION ${{ inputs.version-files }}
shell: bash
- name: Create Pull Request
if: steps.release.outputs.next-version != steps.current-version.outputs.current-version
id: cpr
uses: peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38 # v5.0.2
with:
token: ${{ inputs.token }}
branch: promote/${{ inputs.release-branch }}/to/v${{ steps.release.outputs.next-version }}
base: ${{ inputs.develop-branch }}
branch: promote/${{ inputs.develop-branch }}/to/v${{ steps.release.outputs.next-version }}
title: Release v${{steps.release.outputs.next-version}}
body: |
Merged pull requests to be released:
${{steps.release.outputs.changelog}}
${{ steps.release.outputs.changelog || '- No changes from pull requests.' }}
**Full Changelog**: https://github.com/${{ github.repository }}/compare/v${{ steps.current-version.outputs.current-version }}...${{ inputs.develop-branch }}
commit-message: "chore(release): bump to ${{steps.release.outputs.next-version}}"
delete-branch: true
labels: release
- name: Enable Pull Request Automerge
if: steps.cpr.outputs.pull-request-operation == 'created'
uses: peter-evans/enable-pull-request-automerge@a660677d5469627102a1c1e11409dd063606628d # v3.0.0
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/Adyen/release-automation-action.git"
"url": "git+https://github.com/aleffio/release-automation-action.git"
},
"keywords": [
"actions",
Expand All @@ -30,15 +30,15 @@
},
"devDependencies": {
"@types/node": "^18.16.3",
"@typescript-eslint/parser": "^5.59.2",
"@typescript-eslint/parser": "^5.62.0",
"@vercel/ncc": "^0.36.1",
"eslint": "^8.47.0",
"eslint": "^8.39.0",
"eslint-plugin-github": "^4.7.0",
"eslint-plugin-jest": "^27.2.1",
"jest": "^29.5.0",
"js-yaml": "^4.1.0",
"prettier": "^2.8.8",
"ts-jest": "^29.1.0",
"ts-jest": "^29.1.1",
"typescript": "^5.0.4"
}
}
}

0 comments on commit 7773abb

Please sign in to comment.