Skip to content

Commit

Permalink
apt-get - add retry, apt-get & brew updates
Browse files Browse the repository at this point in the history
_update_ must be specified when only installing packages
  • Loading branch information
MSP-Greg committed Apr 3, 2020
1 parent a94ae52 commit a9b473a
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 34 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@ Installs Bundler using the code from [ruby/setup-ruby].
### apt: (Ubuntu)
List of packages to install. Space delimited. Including `_upgrade_` will do so. `update` is always done.
List of packages to install. Space delimited. Special options are `_update_`, `_upgrade_`, and `_dist-upgrade_`.

If `_upgrade_` or `_dist-upgrade_` are included, `_update_` will also be done.

If neither is included and you're just installing package(s), `_update_` WILL NOT BE DONE unless it's included.


### brew: (macOS)

List of packages to install. Space delimited. Special options are `_update_` and `_upgrade_`.
List of packages to install. Space delimited. Special options are `_update_` and `_upgrade_`, and both work similar to `apt-get:`.

### mingw: (Windows)

Expand Down
30 changes: 23 additions & 7 deletions apt.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,36 @@ const { execSync } = require('./common')
let apt = core.getInput('apt-get').replace(/[^a-z_ \d.-]+/gi, '').trim().toLowerCase()

export const run = async () => {
let needUpdate = true
try {
if (apt !== '') {

if (apt.includes('_upgrade_')) {
execSync('sudo apt-get -qy update')

const opts = '-o Acquire::Retries=3'
let needUpdate = true
let needUpgrade = true

if (/\b_update_\b/.test(apt)) {
execSync(`sudo apt-get ${opts} -qy update`)
apt = apt.replace(/\b_update_\b/gi, '').trim()
needUpdate = false
execSync('sudo apt-get -qy dist-upgrade')
}

if (/\b_dist-upgrade_\b/.test(apt)) {
if (needUpdate) { execSync('sudo apt-get -qy update') }
execSync(`sudo apt-get ${opts} -qy dist-upgrade`)
needUpgrade = false
apt = apt.replace(/\b_dist-upgrade_\b/gi, '').trim()
}

if (/\b_upgrade_\b/.test(apt)) {
if (needUpgrade) {
if (needUpdate) { execSync(`sudo apt-get ${opts} -qy update`) }
execSync(`sudo apt-get ${opts} -qy upgrade`)
}
apt = apt.replace(/\b_upgrade_\b/gi, '').trim()
}

if (apt !== '') {
if (needUpdate) { execSync('sudo apt-get -qy update') }
execSync(`sudo apt-get -qy --no-install-recommends install ${apt}`)
execSync(`sudo apt-get ${opts} -qy --no-install-recommends install ${apt}`)
}
}
} catch (error) {
Expand Down
18 changes: 9 additions & 9 deletions brew.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ let brew = core.getInput('brew').replace(/[^a-z_ \d.@-]+/gi, '').trim().toLowerC
export const run = async () => {
try {
if (brew !== '') {
if (brew.includes('_update_')) {
let needUpdate = true

if (/\b_update_\b/.test(brew)) {
execSync('brew update')
needUpdate = false
brew = brew.replace(/\b_update_\b/gi, '').trim()
}

if (brew.includes('_upgrade_')) {
execSync('brew update')
execSync('brew upgrade')

if (/\b_upgrade_\b/.test(brew)) {
if (needUpdate) { execSync('brew update') }
brew = brew.replace(/\b_upgrade_\b/gi, '').trim()
}

if (brew !== '') {
execSync(`brew install ${brew}`)
}

if (brew !== '') { execSync(`brew install ${brew}`) }
}
} catch (error) {
core.setFailed(error.message)
Expand Down
48 changes: 32 additions & 16 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,36 @@ const { execSync } = __webpack_require__(498)
let apt = core.getInput('apt-get').replace(/[^a-z_ \d.-]+/gi, '').trim().toLowerCase()

const run = async () => {
let needUpdate = true
try {
if (apt !== '') {

if (apt.includes('_upgrade_')) {
execSync('sudo apt-get -qy update')

const opts = '-o Acquire::Retries=3'
let needUpdate = true
let needUpgrade = true

if (/\b_update_\b/.test(apt)) {
execSync(`sudo apt-get ${opts} -qy update`)
apt = apt.replace(/\b_update_\b/gi, '').trim()
needUpdate = false
execSync('sudo apt-get -qy dist-upgrade')
}

if (/\b_dist-upgrade_\b/.test(apt)) {
if (needUpdate) { execSync('sudo apt-get -qy update') }
execSync(`sudo apt-get ${opts} -qy dist-upgrade`)
needUpgrade = false
apt = apt.replace(/\b_dist-upgrade_\b/gi, '').trim()
}

if (/\b_upgrade_\b/.test(apt)) {
if (needUpgrade) {
if (needUpdate) { execSync(`sudo apt-get ${opts} -qy update`) }
execSync(`sudo apt-get ${opts} -qy upgrade`)
}
apt = apt.replace(/\b_upgrade_\b/gi, '').trim()
}

if (apt !== '') {
if (needUpdate) { execSync('sudo apt-get -qy update') }
execSync(`sudo apt-get -qy --no-install-recommends install ${apt}`)
execSync(`sudo apt-get ${opts} -qy --no-install-recommends install ${apt}`)
}
}
} catch (error) {
Expand Down Expand Up @@ -1777,20 +1793,20 @@ let brew = core.getInput('brew').replace(/[^a-z_ \d.@-]+/gi, '').trim().toLowerC
const run = async () => {
try {
if (brew !== '') {
if (brew.includes('_update_')) {
let needUpdate = true

if (/\b_update_\b/.test(brew)) {
execSync('brew update')
needUpdate = false
brew = brew.replace(/\b_update_\b/gi, '').trim()
}

if (brew.includes('_upgrade_')) {
execSync('brew update')
execSync('brew upgrade')

if (/\b_upgrade_\b/.test(brew)) {
if (needUpdate) { execSync('brew update') }
brew = brew.replace(/\b_upgrade_\b/gi, '').trim()
}

if (brew !== '') {
execSync(`brew install ${brew}`)
}

if (brew !== '') { execSync(`brew install ${brew}`) }
}
} catch (error) {
core.setFailed(error.message)
Expand Down

0 comments on commit a9b473a

Please sign in to comment.