Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: improve test workflow #4

Merged
merged 2 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
test-typescript:
name: TypeScript Tests
runs-on: ubuntu-latest

steps:
- name: Checkout
id: checkout
Expand Down Expand Up @@ -46,7 +45,11 @@ jobs:

test-action:
name: GitHub Actions Test
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
- name: Checkout
Expand All @@ -65,3 +68,21 @@ jobs:
AZURE_EMAIL: email
AZURE_REGISTRY_SCOPE: scope
AZURE_ENCODE_PASSWORD: false

- name: Check if file exists
run: |
if [ ! -f ".npmrc" ]; then
echo "File does not exist!"
exit 1
fi
shell: bash
if: ${{ matrix.os != 'windows-latest' }}

- name: Check if file exists
run: |
if (!(Test-Path ".npmrc")) {
Write-Host "File does not exist!"
exit 1
}
shell: powershell
if: ${{ matrix.os == 'windows-latest' }}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
</a>
</p>

[![GitHub Super-Linter](https://github.com/actions/spaceout-ado-npmrc/actions/workflows/linter.yml/badge.svg)](https://github.com/super-linter/super-linter)
![CI](https://github.com/actions/spaceout-ado-npmrc/actions/workflows/ci.yml/badge.svg)
[![GitHub Super-Linter](https://github.com/actions/create-a-azure-dev-ops-npmrc-file/actions/workflows/linter.yml/badge.svg)](https://github.com/super-linter/super-linter)
![CI](https://github.com/actions/create-a-azure-dev-ops-npmrc-file/actions/workflows/ci.yml/badge.svg)

Platforms
![Static Badge](https://img.shields.io/badge/Platform-Windows-blue)![Static Badge](https://img.shields.io/badge/Platform-Linux-blue)![Static Badge](https://img.shields.io/badge/Platform-MacOs-blue)
Expand Down
5 changes: 5 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const runMock = jest.spyOn(main, 'run')
let debugMock: jest.SpiedFunction<typeof core.debug>
let getInputMock: jest.SpiedFunction<typeof core.getInput>
let setFailedMock: jest.SpiedFunction<typeof core.setFailed>
let setInfoMock: jest.SpiedFunction<typeof core.info>

const writeFileSyncMock = jest.spyOn(fs, 'writeFileSync').mockImplementation()

Expand All @@ -36,6 +37,7 @@ describe('action', () => {
debugMock = jest.spyOn(core, 'debug').mockImplementation()
getInputMock = jest.spyOn(core, 'getInput').mockImplementation()
setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation()
setInfoMock = jest.spyOn(core, 'info').mockImplementation()
})

it('should run the action', async () => {
Expand All @@ -50,6 +52,9 @@ describe('action', () => {
expect(debugMock).toHaveBeenCalledWith('Args parsed')
expect(debugMock).toHaveBeenCalledWith('Content generated')
expect(debugMock).toHaveBeenCalledWith('File written')

expect(setInfoMock).toHaveBeenCalled()

expect(writeFileSyncMock).toHaveBeenCalled()
})

Expand Down
4 changes: 4 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ado-npmrc-all-os",
"description": "Azure Dev Ops .npmrc maker for all OS",
"version": "0.0.0",
"version": "0.0.2",
"author": "Luke Celitan, Spaceout.pl",
"private": true,
"homepage": "https://github.com/MassivDash/ado-npmrc-ts-action",
Expand Down
4 changes: 4 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ export async function run(): Promise<void> {
try {
const args = parseArgs()
core.debug('Args parsed')
core.info(`Writing .npmrc file for ${args.AZURE_REGISTRY_NAME} registry`)
const content = generateWriteContent(args)
core.info('Content generated')
core.debug('Content generated')
writeFile(content)
core.debug('File written')
core.info(`File written to ${process.env.GITHUB_WORKSPACE}/.npmrc`)
core.info('Action complete')
} catch (error) {
// Fail the workflow run if an error occurs
if (error instanceof Error) core.setFailed(error.message)
Expand Down