Skip to content

Commit

Permalink
Action-ref warning (#149)
Browse files Browse the repository at this point in the history
* chore: ref warning added

* chore: empty commit

* chore: removed warning conditional

* chore: changed method name

* chore: dist updated

* chore: updated action-ref warning

* chore: build updated

* chore: tests fixed

* chore: actions-tookit updated
  • Loading branch information
sameer-coder committed Mar 1, 2022
1 parent aef9bb2 commit aa144e7
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 2 deletions.
40 changes: 40 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3784,6 +3784,43 @@ exports.request = request;
//# sourceMappingURL=index.js.map


/***/ }),

/***/ 2183:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

"use strict";


const core = __nccwpck_require__(2186)
const github = __nccwpck_require__(5438)

/**
* Displays warning message if the action reference is pinned to master/main
*/
function logActionRefWarning() {
const actionRef = process.env.GITHUB_ACTION_REF
const repoName = github.context.payload.repository.full_name

if (actionRef === 'main' || actionRef === 'master') {
core.warning(
`${repoName} is pinned at HEAD. We strongly ` +
`advise against pinning to "@${actionRef}" as it may be unstable. Please ` +
`update your GitHub Action YAML from:\n\n` +
` uses: '${repoName}@${actionRef}'\n\n` +
`to:\n\n` +
` uses: '${repoName}@<release/tag version>'\n\n` +
`Alternatively, you can pin to any git tag or git SHA in the ` +
`repository.`
)
}
}

module.exports = {
logActionRefWarning
}


/***/ }),

/***/ 3682:
Expand Down Expand Up @@ -9027,6 +9064,7 @@ const core = __nccwpck_require__(2186)
const github = __nccwpck_require__(5438)
const semverMajor = __nccwpck_require__(6688)
const semverCoerce = __nccwpck_require__(3466)
const toolkit = __nccwpck_require__(2183)

const { githubClient } = __nccwpck_require__(3386)
const checkTargetMatchToPR = __nccwpck_require__(7186)
Expand All @@ -9047,6 +9085,8 @@ const {

module.exports = async function run() {
try {
toolkit.logActionRefWarning()

const { pull_request } = github.context.payload

if (!pull_request && !PR_NUMBER) {
Expand Down
152 changes: 150 additions & 2 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"dependencies": {
"@actions/core": "^1.6.0",
"@actions/github": "^5.0.0",
"actions-toolkit": "github:nearform/actions-toolkit",
"semver": "^7.3.5"
},
"devDependencies": {
Expand Down
3 changes: 3 additions & 0 deletions src/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const core = require('@actions/core')
const github = require('@actions/github')
const semverMajor = require('semver/functions/major')
const semverCoerce = require('semver/functions/coerce')
const toolkit = require('actions-toolkit')

const { githubClient } = require('./github-client')
const checkTargetMatchToPR = require('./checkTargetMatchToPR')
Expand All @@ -24,6 +25,8 @@ const {

module.exports = async function run() {
try {
toolkit.logActionRefWarning()

const { pull_request } = github.context.payload

if (!pull_request && !PR_NUMBER) {
Expand Down
5 changes: 5 additions & 0 deletions test/action.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const sinon = require('sinon')
// Stubbing modules
const core = require('@actions/core')
const github = require('@actions/github')
const toolkit = require('actions-toolkit')

const actionLog = require('../src/log')
const actionUtil = require('../src/util')
Expand All @@ -21,6 +22,9 @@ function buildStubbedAction({
}) {

const coreStub = sinon.stub(core)
const toolkitStub = sinon.stub(toolkit, 'logActionRefWarning')
.get(() => sinon.stub())

const githubStub = sinon.stub(github, 'context')
.get(() => { return { payload } })

Expand All @@ -40,6 +44,7 @@ function buildStubbedAction({

const action = proxyquire('../src/action', {
'@actions/core': coreStub,
'actions-toolkit': toolkitStub,
'@actions/github': githubStub,
'./log': logStub,
'./util': utilStub,
Expand Down

0 comments on commit aa144e7

Please sign in to comment.